Python's psutils -- will it reflect CPU Load similar to top/monit?

971 Views Asked by At

I'm writing a program that will perform some logging of my company's webserver load. One information I need to log is the server's CPU Load.

I know that CPU Load -- in monit or top/htop -- reflects the total load across cores, normalized against 1 core. So, for an 8 core server, the total load (when it's heavily loaded) will be higher than 100%. And when all cores are running full load, might reach 800%.

However, monit and top/htop also might show oversubscribed CPU Load, in which the CPU Load number is higher than 800%, indicating that jobs are being queued.

I'm interested in such situation.

My questions:

  1. Does the psutil.cpu_times_percent() function behave the same as monit's/top's CPU Load indicator? That is, will the percentage returned be higher than 100% (cpu_times_percent() normalizes to 100% instead of to 1 core) if there are jobs being queued?

  2. If the answer to #1 is "no", then how can I detect oversubscription / jobs being queued?

1

There are 1 best solutions below

0
On

Yes, psutil.cpu_times_percent() should reflect the same timings as shown by 'top' but of course they cannot be exactly the same, just approximately the same.