Skip to content

Instantly share code, notes, and snippets.

@icedraco
Created August 1, 2017 10:13
Show Gist options
  • Save icedraco/fd2065272453530d0d17edf95fc9c726 to your computer and use it in GitHub Desktop.
Save icedraco/fd2065272453530d0d17edf95fc9c726 to your computer and use it in GitHub Desktop.
Python: Check if system is busy using load average and cpu_count
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