Monday, November 18, 2024
Google search engine
HomeLanguagesPython | os.getloadavg() method

Python | os.getloadavg() method

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.getloadavg() method in Python is used to get the load average over the last 1, 5, and 15 minutes. The load average is the average of the number of processes in the system run queue over a given period of time over 1, 5 and 15 minutes. This method raises OSError if the load average is unobtainable.

Note: This method is available on UNIX platforms only.

Syntax: os.getloadavg()

Parameter: No parameter is required.

Return Type: This method returns a tuple object consisting of float values which denotes the load average over the last 1, 5, and 15 minutes.

Code: Use of os.getloadavg() method to get the load average over the last 1, 5, and 15 minutes.




# Python program to explain os.getloadavg() method  
  
# 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)


Output:

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
RELATED ARTICLES

Most Popular

Recent Comments