summaryrefslogtreecommitdiffstats
path: root/python.d/hddtemp.chart.py
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2017-12-19 23:39:27 +0000
committerFederico Ceratto <federico.ceratto@gmail.com>2017-12-19 23:39:27 +0000
commit6abdfdead1326ccca98dc4cf415c216f1bf25400 (patch)
tree70b803bd499fd45e89627c1b45b90ddf20e8e959 /python.d/hddtemp.chart.py
parentRelease v. 1.8.0+dfsg-1 to Unstable (diff)
parentNew upstream version 1.9.0+dfsg (diff)
downloadnetdata-6abdfdead1326ccca98dc4cf415c216f1bf25400.tar.xz
netdata-6abdfdead1326ccca98dc4cf415c216f1bf25400.zip
Update upstream source from tag 'upstream/1.9.0+dfsg'
Update to upstream version '1.9.0+dfsg' with Debian dir 28b8242a05f9ad26cd1cdbcf078be754fc7d6251
Diffstat (limited to 'python.d/hddtemp.chart.py')
-rw-r--r--python.d/hddtemp.chart.py66
1 files changed, 28 insertions, 38 deletions
diff --git a/python.d/hddtemp.chart.py b/python.d/hddtemp.chart.py
index 8a98995be..577cab09f 100644
--- a/python.d/hddtemp.chart.py
+++ b/python.d/hddtemp.chart.py
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
# Description: hddtemp netdata python.d module
# Author: Pawel Krupa (paulfantom)
-# Modified by l2isbad
+
import os
-from base import SocketService
+from copy import deepcopy
+
+from bases.FrameworkServices.SocketService import SocketService
# default module values (can be overridden per job in `config`)
#update_every = 2
@@ -22,34 +24,39 @@ retries = 60
ORDER = ['temperatures']
+CHARTS = {
+ 'temperatures': {
+ 'options': ['disks_temp', 'Disks Temperatures', 'Celsius', 'temperatures', 'hddtemp.temperatures', 'line'],
+ 'lines': [
+ # lines are created dynamically in `check()` method
+ ]}}
+
+
class Service(SocketService):
def __init__(self, configuration=None, name=None):
SocketService.__init__(self, configuration=configuration, name=name)
+ self.order = ORDER
+ self.definitions = deepcopy(CHARTS)
self._keep_alive = False
self.request = ""
self.host = "127.0.0.1"
self.port = 7634
- self.order = ORDER
- self.fahrenheit = ('Fahrenheit', lambda x: x * 9 / 5 + 32) if self.configuration.get('fahrenheit') else False
- self.whatever = ('Whatever', lambda x: x * 33 / 22 + 11) if self.configuration.get('whatever') else False
- self.choice = (choice for choice in [self.fahrenheit, self.whatever] if choice)
- self.calc = lambda x: x
- self.disks = []
+ self.disks = list()
- def _get_disks(self):
+ def get_disks(self):
try:
disks = self.configuration['devices']
- self.info("Using configured disks" + str(disks))
- except (KeyError, TypeError) as e:
+ self.info("Using configured disks {0}".format(disks))
+ except (KeyError, TypeError):
self.info("Autodetecting disks")
return ["/dev/" + f for f in os.listdir("/dev") if len(f) == 3 and f.startswith("sd")]
- ret = []
+ ret = list()
for disk in disks:
if not disk.startswith('/dev/'):
disk = "/dev/" + disk
ret.append(disk)
- if len(ret) == 0:
+ if not ret:
self.error("Provided disks cannot be found in /dev directory.")
return ret
@@ -59,10 +66,9 @@ class Service(SocketService):
if all(disk in data for disk in self.disks):
return True
-
return False
- def _get_data(self):
+ def get_data(self):
"""
Get data from TCP/IP socket
:return: dict
@@ -72,21 +78,20 @@ class Service(SocketService):
except AttributeError:
self.error("no data received")
return None
- data = {}
+ data = dict()
for i in range(len(raw) // 5):
if not raw[i*5+1] in self.disks:
continue
try:
- val = self.calc(int(raw[i*5+3]))
+ val = int(raw[i*5+3])
except ValueError:
val = 0
data[raw[i*5+1].replace("/dev/", "")] = val
- if len(data) == 0:
+ if not data:
self.error("received data doesn't have needed records")
return None
- else:
- return data
+ return data
def check(self):
"""
@@ -94,27 +99,12 @@ class Service(SocketService):
:return: boolean
"""
self._parse_config()
- self.disks = self._get_disks()
+ self.disks = self.get_disks()
- data = self._get_data()
+ data = self.get_data()
if data is None:
return False
- self.definitions = {
- 'temperatures': {
- 'options': ['disks_temp', 'Disks Temperatures', 'temperatures', 'hddtemp.temperatures', 'line'],
- 'lines': [
- # lines are created dynamically in `check()` method
- ]}
- }
- try:
- self.choice = next(self.choice)
- except StopIteration:
- self.definitions[ORDER[0]]['options'].insert(2, 'Celsius')
- else:
- self.calc = self.choice[1]
- self.definitions[ORDER[0]]['options'].insert(2, self.choice[0])
-
for name in data:
- self.definitions[ORDER[0]]['lines'].append([name])
+ self.definitions['temperatures']['lines'].append([name])
return True