[python-win32] Monitoring CPU Usage

Tim Howgego "tim.nospam at capsu.org" at bag.python.org
Wed Jul 27 00:01:27 CEST 2005


I'm trying to use Python to monitor CPU usage (simple percentage) on 
Windows 98.

First thoughts were to use win32pdh (code similar to 
http://mail.python.org/pipermail/python-win32/2002-April/000347.html ), 
but pdh.dll is not available for Windows 98.

Second thought was to use WMI. WMI isn't native on 98, but it can be 
downloaded and installed. This seems to work, except that 
Win32_Processor "LoadPercentage" returns "None" when running under 
Windows 98.

from win32com.client import GetObject
wmi=GetObject('winmgmts:')
cpu=wmi.InstancesOf('Win32_Processor')
for x in cpu:
... do something with x.Properties_('LoadPercentage').Value

The basic function works, because it does successfully extract other 
data, such as "Name".

For reference: http://msdn.microsoft.com/library/default.asp?url=
/library/en-us/wmisdk/wmi/win32_processor.asp

I'm running Python 2.4.1 with pywin32-204.

If as I suspect, the problem lies in partial WMI support under Windows 
98, does anyone have a better way of trying to extract CPU usage values?

Thanks,

--
Tim Howgego
http://tim.capsu.org/


More information about the Python-win32 mailing list