1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 10:51:13 +01:00

hwmon: Fixed sensor naming

Previously the sensor name was just appeneded to the end of the
previous sensors name.

Now the hwmon name is added as a classifier of the metric.
If the hwmon sensor has a label, the metric will use this for its name,
if it does not then the sensors kind and ID will be used e.g. temp3
This commit is contained in:
Sebastian Goscik 2016-05-06 14:04:29 +01:00
parent 87cbce4244
commit 8abf39762d
2 changed files with 23 additions and 10 deletions

View File

@ -107,13 +107,17 @@ class HwmonInstrument(Instrument):
if report_type == 'diff':
before, after = sensor.readings
diff = conversion(after - before)
context.result.add_metric(sensor.label, diff, units)
context.result.add_metric(sensor.label, diff, units,
classifiers={"hwmon_device": sensor.device_name})
elif report_type == 'before/after':
before, after = sensor.readings
mean = conversion((after + before) / 2)
context.result.add_metric(sensor.label, mean, units)
context.result.add_metric(sensor.label + ' before', conversion(before), units)
context.result.add_metric(sensor.label + ' after', conversion(after), units)
context.result.add_metric(sensor.label, mean, units,
classifiers={"hwmon_device": sensor.device_name})
context.result.add_metric(sensor.label + ' before', conversion(before), units,
classifiers={"hwmon_device": sensor.device_name})
context.result.add_metric(sensor.label + ' after', conversion(after), units,
classifiers={"hwmon_device": sensor.device_name})
else:
raise InstrumentError('Unexpected report_type: {}'.format(report_type))
except ValueError, e:

View File

@ -22,9 +22,10 @@ HWMON_ROOT = '/sys/class/hwmon'
class HwmonSensor(object):
def __init__(self, device, kind, label, filepath):
def __init__(self, device, kind, device_name, label, filepath):
self.device = device
self.kind = kind
self.device_name = device_name
self.label = label
self.filepath = filepath
self.readings = []
@ -58,10 +59,10 @@ def discover_sensors(device, sensor_kinds):
for hwmon_device in hwmon_devices:
try:
device_path = path.join(HWMON_ROOT, hwmon_device, 'device')
name = device.get_sysfile_value(path.join(device_path, 'name'))
base_name = device.get_sysfile_value(path.join(device_path, 'name'))
except DeviceError: # probably a virtual device
device_path = path.join(HWMON_ROOT, hwmon_device)
name = device.get_sysfile_value(path.join(device_path, 'name'))
base_name = device.get_sysfile_value(path.join(device_path, 'name'))
for sensor_kind in sensor_kinds:
i = 1
@ -69,9 +70,17 @@ def discover_sensors(device, sensor_kinds):
while device.file_exists(input_path):
label_path = path.join(device_path, '{}{}_label'.format(sensor_kind, i))
if device.file_exists(label_path):
name += ' ' + device.get_sysfile_value(label_path)
sensors.append(HwmonSensor(device, sensor_kind, name, input_path))
sensors.append(HwmonSensor(device,
sensor_kind,
base_name,
device.get_sysfile_value(label_path),
input_path))
else:
sensors.append(HwmonSensor(device,
sensor_kind,
base_name,
"{}{}".format(sensor_kind, i),
input_path))
i += 1
input_path = path.join(device_path, '{}{}_input'.format(sensor_kind, i))
return sensors