summaryrefslogtreecommitdiffstats
path: root/python.d/sensors.chart.py
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2017-12-19 23:39:21 +0000
committerFederico Ceratto <federico.ceratto@gmail.com>2017-12-19 23:39:21 +0000
commit61aedf201c2c4bf0e5aa4db32e74f4d860b88593 (patch)
treebcf4f9a0cd8bc2daf38b2ff9f29bfcc1e5ed8968 /python.d/sensors.chart.py
parentNew upstream version 1.8.0+dfsg (diff)
downloadnetdata-61aedf201c2c4bf0e5aa4db32e74f4d860b88593.tar.xz
netdata-61aedf201c2c4bf0e5aa4db32e74f4d860b88593.zip
New upstream version 1.9.0+dfsgupstream/1.9.0+dfsg
Diffstat (limited to 'python.d/sensors.chart.py')
-rw-r--r--python.d/sensors.chart.py68
1 files changed, 23 insertions, 45 deletions
diff --git a/python.d/sensors.chart.py b/python.d/sensors.chart.py
index e83aacfd..06e420b6 100644
--- a/python.d/sensors.chart.py
+++ b/python.d/sensors.chart.py
@@ -2,8 +2,8 @@
# Description: sensors netdata python.d plugin
# Author: Pawel Krupa (paulfantom)
-from base import SimpleService
-import lm_sensors as sensors
+from bases.FrameworkServices.SimpleService import SimpleService
+from third_party import lm_sensors as sensors
# default module values (can be overridden per job in `config`)
# update_every = 2
@@ -75,15 +75,12 @@ TYPE_MAP = {
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
- self.order = []
- self.definitions = {}
- self.celsius = ('Celsius', lambda x: x)
- self.fahrenheit = ('Fahrenheit', lambda x: x * 9 / 5 + 32) if self.configuration.get('fahrenheit') else False
- self.choice = (choice for choice in [self.fahrenheit, self.celsius] if choice)
- self.chips = []
+ self.order = list()
+ self.definitions = dict()
+ self.chips = list()
- def _get_data(self):
- data = {}
+ def get_data(self):
+ data = dict()
try:
for chip in sensors.ChipIterator():
prefix = sensors.chip_snprintf_name(chip)
@@ -92,46 +89,39 @@ class Service(SimpleService):
for sf in sfi:
val = sensors.get_value(chip, sf.number)
break
- typeName = TYPE_MAP[feature.type]
- if typeName in LIMITS:
- limit = LIMITS[typeName];
+ type_name = TYPE_MAP[feature.type]
+ if type_name in LIMITS:
+ limit = LIMITS[type_name]
if val < limit[0] or val > limit[1]:
continue
- if 'temp' in str(feature.name.decode()):
- data[prefix + "_" + str(feature.name.decode())] = int(self.calc(val) * 1000)
- else:
data[prefix + "_" + str(feature.name.decode())] = int(val * 1000)
- except Exception as e:
- self.error(e)
+ except Exception as error:
+ self.error(error)
return None
- if len(data) == 0:
- return None
- return data
+ return data or None
- def _create_definitions(self):
- for type in ORDER:
+ def create_definitions(self):
+ for sensor in ORDER:
for chip in sensors.ChipIterator():
chip_name = sensors.chip_snprintf_name(chip)
- if len(self.chips) != 0 and not any([chip_name.startswith(ex) for ex in self.chips]):
+ if self.chips and not any([chip_name.startswith(ex) for ex in self.chips]):
continue
for feature in sensors.FeatureIterator(chip):
sfi = sensors.SubFeatureIterator(chip, feature)
vals = [sensors.get_value(chip, sf.number) for sf in sfi]
if vals[0] == 0:
continue
- if TYPE_MAP[feature.type] == type:
+ if TYPE_MAP[feature.type] == sensor:
# create chart
name = chip_name + "_" + TYPE_MAP[feature.type]
if name not in self.order:
self.order.append(name)
- chart_def = list(CHARTS[type]['options'])
+ chart_def = list(CHARTS[sensor]['options'])
chart_def[1] = chip_name + chart_def[1]
- if chart_def[2] == 'Celsius':
- chart_def[2] = self.choice[0]
self.definitions[name] = {'options': chart_def}
self.definitions[name]['lines'] = []
- line = list(CHARTS[type]['lines'][0])
+ line = list(CHARTS[sensor]['lines'][0])
line[0] = chip_name + "_" + str(feature.name.decode())
line[1] = sensors.get_label(chip, feature)
self.definitions[name]['lines'].append(line)
@@ -139,23 +129,11 @@ class Service(SimpleService):
def check(self):
try:
sensors.init()
- except Exception as e:
- self.error(e)
+ except Exception as error:
+ self.error(error)
return False
-
- try:
- self.choice = next(self.choice)
- except StopIteration:
- # That can not happen but..
- self.choice = ('Celsius', lambda x: x)
- self.calc = self.choice[1]
- else:
- self.calc = self.choice[1]
- try:
- self._create_definitions()
- except Exception as e:
- self.error(e)
- return False
+ self.create_definitions()
return True
+