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.temperature', 'line'],
18 [None, None, 'absolute', 1, 1000]
21 'options': [None, ' voltage', 'Volts', 'voltage', 'sensors.voltage', 'line'],
23 [None, None, 'absolute', 1, 1000]
26 'options': [None, ' current', 'Ampere', 'current', 'sensors.current', '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.fan', '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 'temperature': [-127, 1000],
54 'voltage': [-127, 127],
55 'current': [-127, 127],
75 class Service(SimpleService):
76 def __init__(self, configuration=None, name=None):
77 SimpleService.__init__(self, configuration=configuration, name=name)
85 for chip in sensors.ChipIterator():
86 prefix = sensors.chip_snprintf_name(chip)
87 for feature in sensors.FeatureIterator(chip):
88 sfi = sensors.SubFeatureIterator(chip, feature)
90 val = sensors.get_value(chip, sf.number)
92 typeName = TYPE_MAP[feature.type]
93 if typeName in LIMITS:
94 limit = LIMITS[typeName];
95 if val < limit[0] or val > limit[1]:
97 data[prefix + "_" + str(feature.name.decode())] = int(val * 1000)
98 except Exception as e:
106 def _create_definitions(self):
108 for chip in sensors.ChipIterator():
109 chip_name = sensors.chip_snprintf_name(chip)
110 if len(self.chips) != 0 and not any([chip_name.startswith(ex) for ex in self.chips]):
112 for feature in sensors.FeatureIterator(chip):
113 sfi = sensors.SubFeatureIterator(chip, feature)
114 vals = [sensors.get_value(chip, sf.number) for sf in sfi]
117 if TYPE_MAP[feature.type] == type:
119 name = chip_name + "_" + TYPE_MAP[feature.type]
120 if name not in self.order:
121 self.order.append(name)
122 chart_def = list(CHARTS[type]['options'])
123 chart_def[1] = chip_name + chart_def[1]
124 self.definitions[name] = {'options': chart_def}
125 self.definitions[name]['lines'] = []
126 line = list(CHARTS[type]['lines'][0])
127 line[0] = chip_name + "_" + str(feature.name.decode())
128 line[1] = sensors.get_label(chip, feature)
129 self.definitions[name]['lines'].append(line)
134 except Exception as e:
139 self._create_definitions()
140 except Exception as e: