Performance data
Mark Sass
sassman at nucentrix.net
Sat Jul 14 18:24:20 EDT 2001
Hello,
I am trying to get the current CPU load of a system using the win32
modules, but when I pull the data I get some very small number which seems
to be the CPU load for the machine over a long time (even if I max out the
CPU, I only get small increases in this value). Anyone have a way to get
the current CPU usage that includes both priveleged and user?
counter = '\Processor(_Total)\% Processor Time' #This returns the percent
IDLE time, so my result is 100 - value
def queryperfdata(counter):
machine, object, instance, parentInstance, index, counterName =
win32pdh.ParseCounterPath(counter)
path = win32pdh.MakeCounterPath( ( machine, object, instance, None,
index, counterName) )
# if ValidatePath(path) != 0:
# return None
hq = win32pdh.OpenQuery()
try:
hc = win32pdh.AddCounter(hq, path)
try:
win32pdh.CollectQueryData(hq)
type, result = win32pdh.GetFormattedCounterValue(hc,
win32pdh.PDH_FMT_DOUBLE)
return result
finally:
win32pdh.RemoveCounter(hc)
finally:
win32pdh.CloseQuery(hq)
Any help would be greatly appreciated.
Thanks,
Mark Sass, sassman at nucentrix.net
More information about the Python-list
mailing list