From e0845b0a04d8b87957a85f777fa622b303b869ab Mon Sep 17 00:00:00 2001 From: lgz Date: Sun, 25 Dec 2016 04:00:22 +0900 Subject: add fahrenheit option --- python.d/hddtemp.chart.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'python.d') diff --git a/python.d/hddtemp.chart.py b/python.d/hddtemp.chart.py index 2e7695db54..237666b3b5 100644 --- a/python.d/hddtemp.chart.py +++ b/python.d/hddtemp.chart.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Description: hddtemp netdata python.d module # Author: Pawel Krupa (paulfantom) +# Modified by l2isbad import os from base import SocketService @@ -21,15 +22,6 @@ retries = 60 ORDER = ['temperatures'] -CHARTS = { - 'temperatures': { - 'options': ['disks_temp', 'Disks Temperatures', 'Celsius', 'temperatures', 'hddtemp.temperatures', 'line'], - 'lines': [ - # lines are created dynamically in `check()` method - ]} -} - - class Service(SocketService): def __init__(self, configuration=None, name=None): SocketService.__init__(self, configuration=configuration, name=name) @@ -38,7 +30,10 @@ class Service(SocketService): self.host = "127.0.0.1" self.port = 7634 self.order = ORDER - self.definitions = CHARTS + self.fahrenheit = ('Fahrenheit', lambda x: x * 9 / 5 + 32) if self.configuration.get('fahrenheit') else False + self.whatever = ('Whatever', lambda x: x * 33 / 22 + 11) if self.configuration.get('whatever') else False + self.choice = (choice for choice in [self.fahrenheit, self.whatever] if choice) + self.calc = lambda x: x self.disks = [] def _get_disks(self): @@ -82,12 +77,12 @@ class Service(SocketService): if not raw[i*5+1] in self.disks: continue try: - val = int(raw[i*5+3]) + val = self.calc(int(raw[i*5+3])) except ValueError: val = 0 data[raw[i*5+1].replace("/dev/", "")] = val - if len(data) == 0: + if not data: self.error("received data doesn't have needed records") return None else: @@ -105,9 +100,21 @@ class Service(SocketService): if data is None: return False + self.definitions = { + 'temperatures': { + 'options': ['disks_temp', 'Disks Temperatures', 'temperatures', 'hddtemp.temperatures', 'line'], + 'lines': [ + # lines are created dynamically in `check()` method + ]} + } + try: + self.choice = next(self.choice) + except StopIteration: + self.definitions[ORDER[0]]['options'].insert(2, 'Celsius') + else: + self.calc = self.choice[1] + self.definitions[ORDER[0]]['options'].insert(2, self.choice[0]) + for name in data: self.definitions[ORDER[0]]['lines'].append([name]) - return True - - -- cgit v1.2.3 From a55ebd6d42d6c39484765e8a83e47d3f4d7f4814 Mon Sep 17 00:00:00 2001 From: lgz Date: Sun, 25 Dec 2016 04:06:59 +0900 Subject: add new option to conf file; returned back if in chart.py --- python.d/hddtemp.chart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python.d') diff --git a/python.d/hddtemp.chart.py b/python.d/hddtemp.chart.py index 237666b3b5..8a98995be9 100644 --- a/python.d/hddtemp.chart.py +++ b/python.d/hddtemp.chart.py @@ -82,7 +82,7 @@ class Service(SocketService): val = 0 data[raw[i*5+1].replace("/dev/", "")] = val - if not data: + if len(data) == 0: self.error("received data doesn't have needed records") return None else: -- cgit v1.2.3