Caluclating CPU utilization for a web application running in gunicorn with 4 workers and 4 threads

30 views Asked by At

I have a web application running in gunicorn server with 4 workers and 4 threads, i am using psutil to fetch the cpu utilization as follows

process = psutil.Process(os.getpid())
while True:
   print("cpu Utilization",process.cpu_percent(interval=0)/psutil.cpu_count())

the above code will print cpu percent of each workers pids with cpu_cores

  1. if i want to get overall cpu utilization of the application, how can i get it,

  2. and if the application or process is using only 2 or 3 cpu cores.(psutil.Process().cpu_affinity()) then should i need to caluclate cpu percent by dividing with num of used cores

0

There are 0 answers