os.getloadavg(): How to get the load average of an operating system on a Linux machine

Published on Aug. 22, 2023, 12:14 p.m.

OS module in Python provides functions for interacting. This module provides a portable way of using operating system .

Os.getloadavg() method in Python is used to get the load average .

This method is available only on UNIX platforms.

Syntax: os.getloadavg() No parameter is required. Return Type: This method returns a tuples object with float values that denotes the load average over the last 1, 5, and 15 minutes.

# importing os module 
import os

# Get the load average over
# the last 1, 5, and 15 minutes 
# using os.getloadavg() method
load1, load5, load15 = os.getloadavg()

# Print the load average over
# the last 1, 5, and 15 minutes 
print("Load average over the last 1 minute:", load1)
print("Load average over the last 5 minute:", load5)
print("Load average over the last 15 minute:", load15)
Load average over the last 1 minute: 0.34
Load average over the last 5 minute: 0.42
Load average over the last 15 minute: 0.46