Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

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

share|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

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

share|improve this answer

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

share|improve this answer

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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