Created
August 1, 2017 10:13
-
-
Save icedraco/fd2065272453530d0d17edf95fc9c726 to your computer and use it in GitHub Desktop.
Python: Check if system is busy using load average and cpu_count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_system_busy(threshold=0.5): | |
""" | |
:param float threshold: relative threshold (load_15min/num_cpus) past which the system is considered busy | |
:return: True if the system is considered busy; False otherwise | |
:rtype: bool | |
""" | |
from psutil import cpu_count | |
from os import getloadavg | |
load_1, load_5, load_15 = getloadavg() | |
return load_15 / cpu_count() >= threshold |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment