1 # -*- coding: utf-8 -*-
2 # Description: hddtemp netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
6 from base import SocketService
8 # default module values (can be overridden per job in `config`)
13 # default job configuration (overridden by python.d.plugin)
14 # config = {'local': {
15 # 'update_every': update_every,
17 # 'priority': priority,
18 # 'host': 'localhost',
22 ORDER = ['temperatures']
26 'options': ['disks_temp', 'temperature', 'Celsius', 'Disks temperature', 'hddtemp.temp', 'line'],
28 # lines are created dynamically in `check()` method
33 class Service(SocketService):
34 def __init__(self, configuration=None, name=None):
35 SocketService.__init__(self, configuration=configuration, name=name)
36 self._keep_alive = False
38 self.host = "127.0.0.1"
41 self.definitions = CHARTS
45 def _get_disk_count(self):
46 all_disks = [f for f in os.listdir("/dev") if len(f) == 3 and f.startswith("sd")]
47 for disk in self.exclude:
49 all_disks.remove(disk)
51 self.debug("Disk not found")
54 def _check_raw_data(self, data):
55 if not data.endswith('|'):
58 if data.count('|') % (5 * self.disk_count) == 0:
65 Get data from TCP/IP socket
68 self.disk_count = self._get_disk_count()
70 raw = self._get_raw_data().split("|")[:-1]
71 except AttributeError:
72 self.error("no data received")
75 for i in range(len(raw) // 5):
80 data[raw[i*5+1].replace("/dev/", "")] = val
83 self.error("received data doesn't have needed records")
90 Parse configuration, check if hddtemp is available, and dynamically create chart lines data
95 self.exclude = list(self.configuration['exlude'])
96 except (KeyError, TypeError) as e:
97 self.info("No excluded disks")
99 data = self._get_data()
104 self.definitions[ORDER[0]]['lines'].append([name])