1 # -*- coding: utf-8 -*-
2 # Description: sensors netdata python.d plugin
3 # Author: Pawel Krupa (paulfantom)
5 from base import SimpleService
6 import lm_sensors as sensors
8 # default module values (can be overridden per job in `config`)
11 ORDER = ['temperature', 'fan', 'voltage', 'current', 'power', 'energy', 'humidity']
13 # This is a prototype of chart definition which is used to dynamically create self.definitions
16 'options': [None, ' temperature', 'Celsius', 'temperature', 'sensors.temp', 'line'],
18 [None, None, 'absolute', 1, 1000]
21 'options': [None, ' voltage', 'Volts', 'voltage', 'sensors.volt', 'line'],
23 [None, None, 'absolute', 1, 1000]
26 'options': [None, ' current', 'Ampere', 'current', 'sensors.curr', 'line'],
28 [None, None, 'absolute', 1, 1000]
31 'options': [None, ' power', 'Watt', 'power', 'sensors.power', 'line'],
33 [None, None, 'absolute', 1, 1000000]
36 'options': [None, ' fans speed', 'Rotations/min', 'fans', 'sensors.fans', 'line'],
38 [None, None, 'absolute', 1, 1000]
41 'options': [None, ' energy', 'Joule', 'energy', 'sensors.energy', 'areastack'],
43 [None, None, 'incremental', 1, 1000000]
46 'options': [None, ' humidity', 'Percent', 'humidity', 'sensors.humidity', 'line'],
48 [None, None, 'absolute', 1, 1000]
53 class Service(SimpleService):
54 def __init__(self, configuration=None, name=None):
55 SimpleService.__init__(self, configuration=configuration, name=name)
62 for chip in sensors.iter_detected_chips():
63 prefix = '_'.join(str(chip.path.decode()).split('/')[3:])
66 data[prefix + "_" + str(feature.name.decode())] = feature.get_value() * 1000
67 except Exception as e:
75 def _create_definitions(self):
77 for chip in sensors.iter_detected_chips():
78 prefix = '_'.join(str(chip.path.decode()).split('/')[3:])
82 if feature.get_value() != 0:
84 if sensors.TYPE_DICT[feature.type] == type:
85 name = str(chip.prefix.decode()) + "_" + sensors.TYPE_DICT[feature.type]
86 if name not in self.order:
87 options = list(CHARTS[type]['options'])
88 options[1] = str(chip.prefix) + options[1]
89 self.definitions[name] = {'options': options}
90 self.definitions[name]['lines'] = []
91 self.order.append(name)
92 line = list(CHARTS[type]['lines'][0])
93 line[0] = prefix + "_" + str(feature.name.decode())
94 line[1] = str(feature.label)
95 self.definitions[name]['lines'].append(line)
100 except Exception as e:
104 self._create_definitions()