X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=python.d%2Fsensors.chart.py;h=e83aacfd81c9db1a87ce1f6fb831a6f355a2bf9d;hb=65cd61cc91763c1d95c2c2d2701c1f7be49a3a4c;hp=7abe7f0809d45a5f20f47147501bf8126072544f;hpb=65791a0dab4e0a88ffa46385d6c8afbd1e968158;p=netdata.git diff --git a/python.d/sensors.chart.py b/python.d/sensors.chart.py index 7abe7f08..e83aacfd 100644 --- a/python.d/sensors.chart.py +++ b/python.d/sensors.chart.py @@ -49,6 +49,13 @@ CHARTS = { ]} } +LIMITS = { + 'temperature': [-127, 1000], + 'voltage': [-127, 127], + 'current': [-127, 127], + 'fan': [0, 65535] +} + TYPE_MAP = { 0: 'voltage', 1: 'fan', @@ -70,6 +77,9 @@ class Service(SimpleService): SimpleService.__init__(self, configuration=configuration, name=name) self.order = [] self.definitions = {} + self.celsius = ('Celsius', lambda x: x) + self.fahrenheit = ('Fahrenheit', lambda x: x * 9 / 5 + 32) if self.configuration.get('fahrenheit') else False + self.choice = (choice for choice in [self.fahrenheit, self.celsius] if choice) self.chips = [] def _get_data(self): @@ -82,7 +92,15 @@ class Service(SimpleService): for sf in sfi: val = sensors.get_value(chip, sf.number) break - data[prefix + "_" + str(feature.name.decode())] = int(val * 1000) + typeName = TYPE_MAP[feature.type] + if typeName in LIMITS: + limit = LIMITS[typeName]; + if val < limit[0] or val > limit[1]: + continue + if 'temp' in str(feature.name.decode()): + data[prefix + "_" + str(feature.name.decode())] = int(self.calc(val) * 1000) + else: + data[prefix + "_" + str(feature.name.decode())] = int(val * 1000) except Exception as e: self.error(e) return None @@ -92,7 +110,6 @@ class Service(SimpleService): return data def _create_definitions(self): - prev_chip = "" for type in ORDER: for chip in sensors.ChipIterator(): chip_name = sensors.chip_snprintf_name(chip) @@ -105,19 +122,19 @@ class Service(SimpleService): continue if TYPE_MAP[feature.type] == type: # create chart - if chip_name != prev_chip: - name = chip_name + "_" + TYPE_MAP[feature.type] - if name not in self.order: - self.order.append(name) - chart_def = list(CHARTS[type]['options']) - chart_def[1] = chip_name + chart_def[1] - self.definitions[name] = {'options': chart_def} - self.definitions[name]['lines'] = [] + name = chip_name + "_" + TYPE_MAP[feature.type] + if name not in self.order: + self.order.append(name) + chart_def = list(CHARTS[type]['options']) + chart_def[1] = chip_name + chart_def[1] + if chart_def[2] == 'Celsius': + chart_def[2] = self.choice[0] + self.definitions[name] = {'options': chart_def} + self.definitions[name]['lines'] = [] line = list(CHARTS[type]['lines'][0]) line[0] = chip_name + "_" + str(feature.name.decode()) line[1] = sensors.get_label(chip, feature) self.definitions[name]['lines'].append(line) - prev_chip = chip_name def check(self): try: @@ -125,10 +142,20 @@ class Service(SimpleService): except Exception as e: self.error(e) return False + + try: + self.choice = next(self.choice) + except StopIteration: + # That can not happen but.. + self.choice = ('Celsius', lambda x: x) + self.calc = self.choice[1] + else: + self.calc = self.choice[1] try: self._create_definitions() except Exception as e: self.error(e) return False + return True