up vote 1 down vote favorite
1
share [g+] share [fb]

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
link|improve this question

70% accept rate
Did you install pywin32? – Alex Jurkiewicz Jun 7 '09 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 '09 at 4:51
feedback

4 Answers

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

link|improve this answer
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 '09 at 12:45
What errors did you get? – Alex Jurkiewicz Jun 7 '09 at 13:27
i updated the question. – s.mihai Jun 7 '09 at 13:49
feedback

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

link|improve this answer
feedback

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()
link|improve this answer
feedback

Dirk Paessler forgot to "import os"at very first line

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.