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
69 raw = self._get_raw_data().split("|")[:-1]
70 except AttributeError:
71 self.error("no data received")
74 for i in range(len(raw) // 5):
79 data[raw[i*5+1].replace("/dev/", "")] = val
82 self.error("received data doesn't have needed records")
89 Parse configuration, check if hddtemp is available, and dynamically create chart lines data
94 self.exclude = list(self.configuration['exlude'])
95 except (KeyError, TypeError) as e:
96 self.info("No excluded disks")
100 self.disk_count = int(self.configuration['disk_count'])
101 except (KeyError, TypeError) as e:
102 self.info("Autodetecting number of disks")
103 self.disk_count = self._get_disk_count()
106 data = self._get_data()
111 self.definitions[ORDER[0]]['lines'].append([name])