1 # -*- coding: utf-8 -*-
2 # Description: hddtemp netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
7 from base import SocketService
9 # default module values (can be overridden per job in `config`)
14 # default job configuration (overridden by python.d.plugin)
15 # config = {'local': {
16 # 'update_every': update_every,
18 # 'priority': priority,
19 # 'host': 'localhost',
23 ORDER = ['temperatures']
25 class Service(SocketService):
26 def __init__(self, configuration=None, name=None):
27 SocketService.__init__(self, configuration=configuration, name=name)
28 self._keep_alive = False
30 self.host = "127.0.0.1"
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
41 disks = self.configuration['devices']
42 self.info("Using configured disks" + str(disks))
43 except (KeyError, TypeError) as e:
44 self.info("Autodetecting disks")
45 return ["/dev/" + f for f in os.listdir("/dev") if len(f) == 3 and f.startswith("sd")]
49 if not disk.startswith('/dev/'):
53 self.error("Provided disks cannot be found in /dev directory.")
56 def _check_raw_data(self, data):
57 if not data.endswith('|'):
60 if all(disk in data for disk in self.disks):
67 Get data from TCP/IP socket
71 raw = self._get_raw_data().split("|")[:-1]
72 except AttributeError:
73 self.error("no data received")
76 for i in range(len(raw) // 5):
77 if not raw[i*5+1] in self.disks:
80 val = self.calc(int(raw[i*5+3]))
83 data[raw[i*5+1].replace("/dev/", "")] = val
86 self.error("received data doesn't have needed records")
93 Parse configuration, check if hddtemp is available, and dynamically create chart lines data
97 self.disks = self._get_disks()
99 data = self._get_data()
105 'options': ['disks_temp', 'Disks Temperatures', 'temperatures', 'hddtemp.temperatures', 'line'],
107 # lines are created dynamically in `check()` method
111 self.choice = next(self.choice)
112 except StopIteration:
113 self.definitions[ORDER[0]]['options'].insert(2, 'Celsius')
115 self.calc = self.choice[1]
116 self.definitions[ORDER[0]]['options'].insert(2, self.choice[0])
119 self.definitions[ORDER[0]]['lines'].append([name])