Beispiel #1
0
def get_sensor_reading(name, ipmicmd):
    value = None
    sensor = None
    health = pygconst.Health.Ok
    states = []
    if name in fpc_sensors and 'elements' not in fpc_sensors[name]:
        sensor = fpc_sensors[name]
        value = sensor['provider'](ipmicmd)
    else:
        bname, _, idx = name.rpartition(' ')
        idx = int(idx)
        if bname in fpc_sensors and idx <= fpc_sensors[bname]['elements']:
            sensor = fpc_sensors[bname]
            if 'returns' in sensor:
                health, states = sensor['provider'](ipmicmd, idx)
            else:
                value = sensor['provider'](ipmicmd, idx)
    if sensor is not None:
        return sdr.SensorReading(
            {
                'name': name,
                'imprecision': None,
                'value': value,
                'states': states,
                'state_ids': [],
                'health': health,
                'type': sensor['type']
            }, sensor['units'])
    raise Exception('Sensor not found: ' + name)
Beispiel #2
0
class Energy(object):
    def __init__(self, ipmicmd):
        self.ipmicmd = ipmicmd

    def get_energy_sensor(self):
        """read the cpu usage        
        """
        try:
            rsp = self.ipmicmd.xraw_command(netfn=0x04,
                                            command=0x2d,
                                            bridge_request={
                                                "addr": 0x2c,
                                                "channel": 0x06
                                            },
                                            data=[0xbe])
        except pygexc.IpmiException, ie:
            return

        cpu_usage = ord(rsp["data"][0]) * 100 / 0xff
        #mimic the power sensor
        temp = {
            'name': "CPU_Usage",
            'health': const.Health.Ok,
            'states': [],
            'state_ids': [],
            'type': "Processor",
            'units': "%",
            'value': cpu_usage,
            'imprecision': None
        }
        yield (sdr.SensorReading(temp, temp['units']))
Beispiel #3
0
 def get_energy_sensor(self):
     snapshot_buffer = self.read_snapshot_buffer()
     
     #search the metering data if server supports subsystem power metering
     if self.has_subsystem_metering and len(snapshot_buffer) > 37:
         start = len(snapshot_buffer) - 37
         found_cpu_power = False
         found_mem_power = False
         #search the pattern from tail, only for CPU(0) / MEM(1) / PSU(2) / FAN(3)
         for i in range(4):
             #metering data start from: count (1 byte), subsystem type (1 byte), subsystem power metering (8 bytes)...
             if ord(snapshot_buffer[start + i*9]) == 4-i:
                 found_subsystem = True
                 sub_start = start + 1 + i*9 
                 for j in range(4-i):
                     if not ord(snapshot_buffer[sub_start + j*9]) in (1, 2, 3, 4):
                         found_subsystem = False
                         break
                 if found_subsystem:
                     start = start + i*9
                     index = 0
                     while index < ord(snapshot_buffer[start]):
                         #CPU power metering
                         if ord(snapshot_buffer[start + 1 + index*9]) == 0x01:
                             temp = ''.join(snapshot_buffer[start + 2 + index*9 : start + 10 + index*9])
                             self.cpu_power = struct.unpack('>Q', temp)[0]
                             found_cpu_power = True
                         #Memory power metering 
                         elif ord(snapshot_buffer[start + 1 + index*9]) == 0x02:
                             temp = ''.join(snapshot_buffer[start + 2 + index*9 : start + 10 + index*9])
                             self.memory_power = struct.unpack('>Q', temp)[0]
                             found_mem_power = True
                         index += 1
                     if self.has_timestamp:
                         temp = ''.join(snapshot_buffer[start-8 : start])
                         self.timestamp = struct.unpack('>Q', temp)[0]      
                     break
                 
         #mimic the power sensor        
         if found_cpu_power and self.timestamp:
             temp = {'name': "CPU Power", 'health': const.Health.Ok, 'states': [], 'state_ids': [self.timestamp], 
                     'type': "Current", 'units': "millijoule", 'value': self.cpu_power, 'imprecision' : None}
             yield(sdr.SensorReading(temp, temp['units']))
         if found_mem_power and self.timestamp:
             temp = {'name': "MEM Power", 'health': const.Health.Ok, 'states': [], 'state_ids': [self.timestamp],
                     'type': "Current", 'units': "millijoule", 'value': self.memory_power, 'imprecision' : None}
             yield(sdr.SensorReading(temp, temp['units']))
Beispiel #4
0
 def get_oem_sensor_reading(self, name, ipmicmd):
     if self._energymanager is None:
         self._energymanager = energy.EnergyManager(ipmicmd)
     if name == 'AC Energy':
         kwh = self._energymanager.get_ac_energy(ipmicmd)
     elif name == 'DC Energy':
         kwh = self._energymanager.get_dc_energy(ipmicmd)
     else:
         raise pygexc.UnsupportedFunctionality('No sunch sensor ' + name)
     return sdr.SensorReading({'name': name, 'imprecision': None,
                               'value': kwh, 'states': [],
                               'state_ids': [],
                               'health': pygconst.Health.Ok,
                               'type': 'Energy'}, 'kWh')