The os.getloadavg()
function is used to extract the averages of the number of running processes over the last 1, 5, and 15 minutes, respectively. Load average is the mean value of processes executed over a period of time.
The Python OS module helps to interact with operating system command as an interface.
# Signatureos.getloadavg()
It does not take any argument value.
It returns a tuple containing three float values representing the load averages over the last 1, 5, and 15 minutes, respectively.
The getloadavg()
function also throws an OSError
exception when the load average is unobtainable, or the function fails to determine it.
# Program using getloadavg() function# including os moduleimport os# extracting load averagesvalues = os.getloadavg()# print load averages of previous 1, 5 and 15 minutesprint("Load Averages:", values)
In the above code snippet, we are invoking os.getloadavg()
to get load averages over the last 1, 5, and 15 minutes.
getloadavg()
function and store the returned tuple of averages in the values
variable.# Program using getloadavg() function# including os moduleimport os# extract load average valuesLoad1, Load5, Load15 = os.getloadavg()# show the load averagesprint("Load average over last 1 minute:", Load1)print("Load average over last 5 minute:", Load5)print("Load average over last 15 minute:", Load15)
os.getloadavg()
function and store the load averages in Load1
(load average of the last 1 minute), Load5
(load average of the last 5 minutes) and Load15
(load average of the last 15 minutes) separately.