Monitor Windows CPU usage with Python

This little Python script lets you monitor the average CPU-load on a Windows machine. Needs WMI to be present.

import os

def get_cpu_load():
    """ Returns a list CPU Loads"""
    result = []
    cmd = "WMIC CPU GET LoadPercentage "
    response = os.popen(cmd + ' 2>&1','r').read().strip().split("\r\n")
    for load in response[1:]:
       result.append(int(load))
    return result

if __name__ == '__main__':
    print get_cpu_load()
Published in: on June 8, 2009 at 10:25 am  Comments (5)