Wednesday, February 6, 2008

Performance Counters - Python

The module win32pdh allows to retrieve performance counters on Windows host
Here is an example published on ASPN.
You will have to use "win32pdhutil.browse" to translate counters names
in your language.


import win32pdh
import win32pdhutil

#Use win32pdh, Kevan Heydon, 2006/06/23
#http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496815

#win32pdhutil.browse()

def uptimeServeur(serveur='Python'):
path = win32pdh.MakeCounterPath( ( serveur, 'Système', None, None, 0, "Temps d'activité système") )
query = win32pdh.OpenQuery()
handle = win32pdh.AddCounter( query, path )
win32pdh.CollectQueryData( query )
seconds = win32pdh.GetFormattedCounterValue( handle, win32pdh.PDH_FMT_LONG | win32pdh.PDH_FMT_NOSCALE )[ 1 ]
return "Serveur : %s - Uptime: %d seconds" %(serveur,seconds )

print uptimeServeur()

No comments:

Post a Comment