diff options
author | nicolargo <nicolas@nicolargo.com> | 2022-07-14 10:33:52 +0200 |
---|---|---|
committer | nicolargo <nicolas@nicolargo.com> | 2022-07-14 10:33:52 +0200 |
commit | 2ffb54a29156bb14b28e42a130c03f904ca5c626 (patch) | |
tree | d2f4edd5c6fd0dcf7b4a79f5ca5e2751f6e4e480 | |
parent | 678f6da3a95964b67b80505326bac3729800b671 (diff) |
In the sensor plugin thresholds in the configuration file should overwrite system ones #2058
-rw-r--r-- | glances/plugins/glances_plugin.py | 6 | ||||
-rw-r--r-- | glances/plugins/glances_sensors.py | 36 |
2 files changed, 23 insertions, 19 deletions
diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index a048f031..22a409a4 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -18,7 +18,7 @@ import json import copy from operator import itemgetter -from glances.compat import iterkeys, itervalues, listkeys, map, mean, nativestr, u +from glances.compat import iterkeys, itervalues, listkeys, map, mean, nativestr from glances.actions import GlancesActions from glances.history import GlancesHistory from glances.logger import logger @@ -1102,7 +1102,7 @@ class GlancesPlugin(object): """ symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y') if min_symbol in symbols: - symbols = symbols[symbols.index(min_symbol) :] + symbols = symbols[symbols.index(min_symbol):] prefix = { 'Y': 1208925819614629174706176, 'Z': 1180591620717411303424, @@ -1180,7 +1180,7 @@ class GlancesPlugin(object): "%s %s %s return %s in %s seconds" % ( args[0].__class__.__name__, - args[0].__class__.__module__[len('glances_') :], + args[0].__class__.__module__[len('glances_'):], fct.__name__, ret, duration, diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py index 2f5c7f3d..14bb40d9 100644 --- a/glances/plugins/glances_sensors.py +++ b/glances/plugins/glances_sensors.py @@ -114,7 +114,6 @@ class Plugin(GlancesPlugin): # Update stats using SNMP # No standard: # http://www.net-snmp.org/wiki/index.php/Net-SNMP_and_lm-sensors_on_Ubuntu_10.04 - pass # Global change on stats @@ -160,17 +159,22 @@ class Plugin(GlancesPlugin): if not i['value']: continue # Alert processing - if i['type'] == 'temperature_core' and not self.is_limit('critical', stat_name=i['type']): - if i['critical'] is None: - alert = 'DEFAULT' - elif i['value'] >= i['critical']: - alert = 'CRITICAL' - elif i['warning'] is None: - alert = 'DEFAULT' - elif i['value'] >= i['warning']: - alert = 'WARNING' + if i['type'] == 'temperature_core': + if self.is_limit('critical', stat_name='sensors_temperature_' + i['label']): + # By default use the thresholds confiured in the glances.conf file (see #2058) + alert = self.get_alert(current=i['value'], header='temperature_' + i['label']) else: - alert = 'OK' + # Else use the system thresholds + if i['critical'] is None: + alert = 'DEFAULT' + elif i['value'] >= i['critical']: + alert = 'CRITICAL' + elif i['warning'] is None: + alert = 'DEFAULT' + elif i['value'] >= i['warning']: + alert = 'WARNING' + else: + alert = 'OK' elif i['type'] == 'battery': alert = self.get_alert(current=100 - i['value'], header=i['type']) else: @@ -322,12 +326,12 @@ class GlancesGrabSensors(object): else: sensors_current['label'] = feature.label # Sensors value, limit and unit - sensors_current['value'] = int(getattr(feature, 'current', 0) if getattr(feature, 'current', 0) else 0) - warning = getattr(feature, 'high', None) - sensors_current['warning'] = int(warning) if warning is not None else None - critical = getattr(feature, 'critical', None) - sensors_current['critical'] = int(critical) if critical is not None else None sensors_current['unit'] = type + sensors_current['value'] = int(getattr(feature, 'current', 0) if getattr(feature, 'current', 0) else 0) + system_warning = getattr(feature, 'high', None) + system_critical = getattr(feature, 'critical', None) + sensors_current['warning'] = int(system_warning) if system_warning is not None else None + sensors_current['critical'] = int(system_critical) if system_critical is not None else None # Add sensor to the list ret.append(sensors_current) i += 1 |