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)
63 for chip in sensors.iter_detected_chips():
64 prefix = '_'.join(str(chip.path.decode()).split('/')[3:])
67 data[prefix + "_" + str(feature.name.decode())] = feature.get_value() * 1000
68 except Exception as e:
76 def _create_definitions(self):
78 for chip in sensors.iter_detected_chips():
79 prefix = '_'.join(str(chip.path.decode()).split('/')[3:])
82 pref = str(chip.prefix.decode())
83 if len(self.chips) != 0 and not any([ex.startswith(pref) for ex in self.chips]):
87 float(feature.get_value())
90 if feature.get_value() < 0:
92 if sensors.TYPE_DICT[feature.type] == type:
93 name = pref + "_" + sensors.TYPE_DICT[feature.type]
94 if name not in self.order:
95 options = list(CHARTS[type]['options'])
96 options[1] = pref + options[1]
97 self.definitions[name] = {'options': options}
98 self.definitions[name]['lines'] = []
99 self.order.append(name)
100 line = list(CHARTS[type]['lines'][0])
101 line[0] = prefix + "_" + str(feature.name.decode())
102 line[1] = str(feature.label)
103 self.definitions[name]['lines'].append(line)
107 self.chips = list(self.configuration['chips'])
108 except (KeyError, TypeError):
109 self.error("No path to log specified. Using all chips.")
112 ORDER = list(self.configuration['types'])
113 except (KeyError, TypeError):
114 self.error("No path to log specified. Using all sensor types.")
117 except Exception as e:
121 self._create_definitions()
125 if len(self.definitions) == 0:
126 self.error("No sensors found")