@cryptotaxi247 / netdata-1 / commits / e0845b0a0

add fahrenheit option

lgz committed Dec 25, 2016 at 04:00 UTC e0845b0a04d8b87957a85f777fa622b303b869ab
1 file changed +22 -15
python.d/hddtemp.chart.py
+22 -15
@@ -1,6 +1,7 @@
1 # -*- coding: utf-8 -*-
2 # Description: hddtemp netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
4 +# Modified by l2isbad
5
6 import os
7 from base import SocketService
@@ -21,15 +22,6 @@ retries = 60
22
23 ORDER = ['temperatures']
24
24 -CHARTS = {
25 - 'temperatures': {
26 - 'options': ['disks_temp', 'Disks Temperatures', 'Celsius', 'temperatures', 'hddtemp.temperatures', 'line'],
27 - 'lines': [
28 - # lines are created dynamically in `check()` method
29 - ]}
30 -}
31 -
32 -
25 class Service(SocketService):
26 def __init__(self, configuration=None, name=None):
27 SocketService.__init__(self, configuration=configuration, name=name)
@@ -38,7 +30,10 @@ class Service(SocketService):
30 self.host = "127.0.0.1"
31 self.port = 7634
32 self.order = ORDER
41 - self.definitions = CHARTS
33 + self.fahrenheit = ('Fahrenheit', lambda x: x * 9 / 5 + 32) if self.configuration.get('fahrenheit') else False
34 + self.whatever = ('Whatever', lambda x: x * 33 / 22 + 11) if self.configuration.get('whatever') else False
35 + self.choice = (choice for choice in [self.fahrenheit, self.whatever] if choice)
36 + self.calc = lambda x: x
37 self.disks = []
38
39 def _get_disks(self):
@@ -82,12 +77,12 @@ class Service(SocketService):
77 if not raw[i*5+1] in self.disks:
78 continue
79 try:
85 - val = int(raw[i*5+3])
80 + val = self.calc(int(raw[i*5+3]))
81 except ValueError:
82 val = 0
83 data[raw[i*5+1].replace("/dev/", "")] = val
84
90 - if len(data) == 0:
85 + if not data:
86 self.error("received data doesn't have needed records")
87 return None
88 else:
@@ -105,9 +100,21 @@ class Service(SocketService):
100 if data is None:
101 return False
102
103 + self.definitions = {
104 + 'temperatures': {
105 + 'options': ['disks_temp', 'Disks Temperatures', 'temperatures', 'hddtemp.temperatures', 'line'],
106 + 'lines': [
107 + # lines are created dynamically in `check()` method
108 + ]}
109 + }
110 + try:
111 + self.choice = next(self.choice)
112 + except StopIteration:
113 + self.definitions[ORDER[0]]['options'].insert(2, 'Celsius')
114 + else:
115 + self.calc = self.choice[1]
116 + self.definitions[ORDER[0]]['options'].insert(2, self.choice[0])
117 +
118 for name in data:
119 self.definitions[ORDER[0]]['lines'].append([name])
110 -
120 return True
112 -
113 -