Skip to content
Related Articles

Related Articles

Improve Article

Python | os.getloadavg() method

  • Last Updated : 25 Jun, 2019

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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :