@cryptotaxi247 / netdata-1 / commits / bc3369515

working version of `hddtemp.chart.py`

paulfantom committed Jul 3, 2016 at 15:15 UTC bc3369515b306a6241e31199839717b315974b8f
2 files changed +88 -1
python.d/apache_cache.chart.py
+1 -1
@@ -6,7 +6,7 @@ from base import LogService
6
7 priority = 60000
8 retries = 5
9 -update_every = 3
9 +# update_every = 3
10
11 ORDER = ['cache']
12 CHARTS = {
python.d/hddtemp.chart.py new
+87
@@ -0,0 +1,87 @@
1 +# -*- coding: utf-8 -*-
2 +# Description: hddtemp netdata python.d plugin
3 +# Author: Pawel Krupa (paulfantom)
4 +
5 +from base import SimpleService
6 +import socket
7 +
8 +# default module values (can be overridden per job in `config`)
9 +#update_every = 2
10 +priority = 60000
11 +retries = 5
12 +
13 +# default job configuration (overridden by python.d.plugin)
14 +# config = {'local': {
15 +# 'update_every': update_every,
16 +# 'retries': retries,
17 +# 'priority': priority,
18 +# 'host': 'localhost',
19 +# 'port': 7634
20 +# }}
21 +
22 +ORDER = ['temperatures']
23 +
24 +CHARTS = {
25 + 'temperatures': {
26 + 'options': ['disks_temp', 'temperature', 'Celsius', 'Disks temperature', 'hddtemp.temp', 'line'],
27 + 'lines': [
28 + # lines are created dynamically in `check()` method
29 + ]}
30 +}
31 +
32 +
33 +class Service(SimpleService):
34 + def __init__(self, configuration=None, name=None):
35 + self.host = "localhost"
36 + self.port = 7634
37 + SimpleService.__init__(self, configuration=configuration, name=name)
38 + self.order = ORDER
39 + self.definitions = CHARTS
40 +
41 + def _get_data(self):
42 + """
43 + Get data from TCP/IP socket
44 + :return: dict
45 + """
46 + try:
47 + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
48 + s.connect((self.host, self.port))
49 + raw = s.recv(4096).split("|")[:-1]
50 + s.close()
51 + except Exception:
52 + return None
53 +
54 + data = {}
55 + for i in range(len(raw) // 5):
56 + try:
57 + val = int(raw[i*5+3])
58 + except ValueError:
59 + val = 0
60 + data[raw[i*5+1].replace("/dev/", "")] = val
61 + return data
62 +
63 + def check(self):
64 + if self.name is not None or self.name != str(None):
65 + self.name = ""
66 + else:
67 + self.name = str(self.name)
68 + try:
69 + self.host = str(self.configuration['host'])
70 + except (KeyError, TypeError):
71 + self.error("No host specified. Using: '" + self.host + "'")
72 + try:
73 + self.port = int(self.configuration['port'])
74 + except (KeyError, TypeError):
75 + self.error("No port specified. Using: '" + str(self.port) + "'")
76 +
77 + data = self._get_data()
78 + if data is None:
79 + self.error("No data received")
80 + return False
81 +
82 + for name in data:
83 + self.definitions[ORDER[0]]['lines'].append([name])
84 +
85 + return True
86 +
87 +