1

Anyone using a Python script to monitor CPU usage on a Windows machine ? i've google for some time but have not been able to find any usable script. could you guys show me some example of what you're using ?

Here is the errors i got.

    Traceback (most recent call last):
  File "test.py", line 1, in 
    import wmi
  File "c:\Python26\lib\site-packages\wmi.py", line 141, in 
    from win32com.client import GetObject, Dispatch
ImportError: No module named win32com.client
2
  • Did you install pywin32?
    – Alex J
    Jun 7, 2009 at 14:34
  • howdy, i installed win32 on another machine and it works like a charm. for my developing app i decided to use perl instead, since the ActivePerl package installer is very easy to use, and permits me to search and add what pachets i do need
    – s.mihai
    Jun 8, 2009 at 4:51

4 Answers 4

2

Us psutil module, it provides for memory, cpu, netowrk, etc usages. Visit their project webpage http://code.google.com/p/psutil/ .

1

Lucky ol' you gets to dig around in WMI. Check out the Python module 'wmi' which is about as good as I've seen.

3
  • i tried that one, i just wasn't able to get that module installed, and i thought there was some other way to achieve this task.
    – s.mihai
    Jun 7, 2009 at 12:45
  • What errors did you get?
    – Alex J
    Jun 7, 2009 at 13:27
  • i updated the question.
    – s.mihai
    Jun 7, 2009 at 13:49
1

You are missing the python win32 extensions which you can find here.

0

This blog entry shows some code:

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()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .