class SystemDataCollector: """The class in charge of getting the CPU load""" def __init__(self, refresh_rate_in_sec): """Constructor""" self._simu = SimulatorRpcClient() self._max_count = refresh_rate_in_sec * 10 self._count = self._max_count-1 def collect(self): """get the CPU load thanks to WMI""" try: self._count += 1 if self._count >= self._max_count: self._count = 0 #WMI get the load percentage of the machine from win32com.client import GetObject wmi = GetObject('winmgmts:') cpu = wmi.InstancesOf('Win32_Processor') for (_cpu, i) in zip(cpu, xrange(10)): value = _cpu.Properties_('LoadPercentage').Value cpu_usage = int(str(value)) if value else 0 #execute a RPC command for changing the value self._simu.set_values(1, "Cpu", i, (cpu_usage, )) except Exception, excpt: LOGGER.debug("SystemDataCollector error: %s", str(excpt)) time.sleep(0.1)
class SystemDataCollector: """The class in charge of getting the CPU load""" def __init__(self, refresh_rate_in_sec): """Constructor""" self._simu = SimulatorRpcClient() self._max_count = refresh_rate_in_sec * 10 self._count = self._max_count-1 def collect(self): """get the CPU load thanks to WMI""" try: self._count += 1 if self._count >= self._max_count: self._count = 0 print "Quering data via SNMP" temp = queryTemperature() # remove when changing OID temp = temp % 100 print "Data received via SNMP: %d" % temp self._simu.set_values(1, "Temp", 1, (temp, )) except Exception, excpt: LOGGER.debug("SystemDataCollector error: %s", str(excpt)) time.sleep(0.1)
def __init__(self, refresh_rate_in_sec): """Constructor""" self._simu = SimulatorRpcClient() self._max_count = refresh_rate_in_sec * 10 self._count = self._max_count-1