1 # -*- coding: utf-8 -*-
2 # Description: sensors netdata python.d plugin
3 # Author: Pawel Krupa (paulfantom)
5 from base import SimpleService
6 import new_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]
68 class Service(SimpleService):
69 def __init__(self, configuration=None, name=None):
70 SimpleService.__init__(self, configuration=configuration, name=name)
78 for chip in sensors.ChipIterator():
79 prefix = sensors.chip_snprintf_name(chip)
80 for feature in sensors.FeatureIterator(chip):
81 sfi = sensors.SubFeatureIterator(chip, feature)
83 val = sensors.get_value(chip, sf.number)
85 data[prefix + "_" + str(feature.name.decode())] = int(val * 1000)
86 except Exception as e:
94 def _create_definitions(self):
97 for chip in sensors.ChipIterator():
98 chip_name = sensors.chip_snprintf_name(chip)
99 if len(self.chips) != 0 and not any([chip_name.startswith(ex) for ex in self.chips]):
101 for feature in sensors.FeatureIterator(chip):
102 sfi = sensors.SubFeatureIterator(chip, feature)
103 vals = [sensors.get_value(chip, sf.number) for sf in sfi]
106 if TYPE_MAP[feature.type] == type:
108 if chip_name != prev_chip:
109 name = chip_name + "_" + TYPE_MAP[feature.type]
110 if name not in self.order:
111 self.order.append(name)
112 chart_def = list(CHARTS[type]['options'])
113 chart_def[1] = chip_name + chart_def[1]
114 self.definitions[name] = {'options': chart_def}
115 self.definitions[name]['lines'] = []
116 line = list(CHARTS[type]['lines'][0])
117 line[0] = chip_name + "_" + str(feature.name.decode())
118 line[1] = sensors.get_label(chip, feature)
119 self.definitions[name]['lines'].append(line)
120 prev_chip = chip_name
125 except Exception as e:
130 self._create_definitions()
131 except Exception as e: