-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CPU usage percentage #3
Comments
So, following this guide: https://github.com/Leo-G/DevopsWiki/wiki/How-Linux-CPU-Usage-Time-and-Percentage-is-calculated#formula The right way to calculate is this: total_time_used = Psutil.cpu_times.first.user + Psutil.cpu_times.first.system + Psutil.cpu_times.first.nice + Psutil.cpu_times.first.nice + Psutil.cpu_times.first.softirq + Psutil.cpu_times.first.irq + Psutil.cpu_times.first.steal + Psutil.cpu_times.first.idle + Psutil.cpu_times.first.iowait
total_time_idle = Psutil.cpu_times.first.iowait + Psutil.cpu_times.first.idle
time_used = total_time_used - total_time_idle
time_used / total_time_used * 100 # this is the % of cpu used |
@kodnaplakal Maybe it can be nice to add a small method for this? |
@bararchy For calculate CPU usage you need interval, take Psutil.cpu_times sleep N take Psutil.cpu_times again and see difference. |
@bararchy if you can do it yourself, please create a PR if not I will do it today. |
Would you say this should give me the best overall % of CPU usage?
The text was updated successfully, but these errors were encountered: