sensors module fix (#4651)
* sensors: survive sensors.get_value Exception * sensors: log unreadable subfeature in check * sensors: add todos
Ilya Mashchenko committed
Nov 14, 2018 at 05:14 UTC
d0cc7910da089afae565b86bd86ef674df6ef838
1 file changed
+29
-6
collectors/python.d.plugin/sensors/sensors.chart.py
+29
-6
@@ -3,13 +3,22 @@
3
# Author: Pawel Krupa (paulfantom)
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
6
-from bases.FrameworkServices.SimpleService import SimpleService
6
from third_party import lm_sensors as sensors
7
8
+from bases.FrameworkServices.SimpleService import SimpleService
9
+
10
# default module values (can be overridden per job in `config`)
11
# update_every = 2
12
12
-ORDER = ['temperature', 'fan', 'voltage', 'current', 'power', 'energy', 'humidity']
13
+ORDER = [
14
+ 'temperature',
15
+ 'fan',
16
+ 'voltage',
17
+ 'current',
18
+ 'power',
19
+ 'energy',
20
+ 'humidity',
21
+]
22
23
# This is a prototype of chart definition which is used to dynamically create self.definitions
24
CHARTS = {
@@ -94,9 +103,16 @@ class Service(SimpleService):
103
prefix = sensors.chip_snprintf_name(chip)
104
for feature in sensors.FeatureIterator(chip):
105
sfi = sensors.SubFeatureIterator(chip, feature)
106
+ val = None
107
for sf in sfi:
98
- val = sensors.get_value(chip, sf.number)
99
- break
108
+ try:
109
+ val = sensors.get_value(chip, sf.number)
110
+ break
111
+ # TODO: use specific error after upstream is fixed
112
+ except Exception:
113
+ continue
114
+ if val is None:
115
+ continue
116
type_name = TYPE_MAP[feature.type]
117
if type_name in LIMITS:
118
limit = LIMITS[type_name]
@@ -117,8 +133,15 @@ class Service(SimpleService):
133
continue
134
for feature in sensors.FeatureIterator(chip):
135
sfi = sensors.SubFeatureIterator(chip, feature)
120
- vals = [sensors.get_value(chip, sf.number) for sf in sfi]
121
- if vals[0] == 0:
136
+ vals = list()
137
+ for sf in sfi:
138
+ try:
139
+ vals.append(sensors.get_value(chip, sf.number))
140
+ # TODO: use specific error after upstream is fixed
141
+ except Exception as error:
142
+ self.error('{0}: {1}'.format(sf.name, error))
143
+ continue
144
+ if not vals or vals[0] == 0:
145
continue
146
if TYPE_MAP[feature.type] == sensor:
147
# create chart