diff options
-rw-r--r-- | conf/glances.conf | 2 | ||||
-rwxr-xr-x | docker-compose/glances.conf | 2 | ||||
-rw-r--r-- | glances/plugins/plugin/model.py | 68 | ||||
-rw-r--r-- | glances/plugins/sensors/__init__.py | 7 |
4 files changed, 43 insertions, 36 deletions
diff --git a/conf/glances.conf b/conf/glances.conf index a7ed6374..25a5d5a1 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -354,6 +354,8 @@ temperature_hdd_critical=60 battery_careful=80 battery_warning=90 battery_critical=95 +# Fan speed threashold in RPM +#fan_speed_careful=100 # Sensors alias #alias=core 0:CPU Core 0,core 1:CPU Core 1 diff --git a/docker-compose/glances.conf b/docker-compose/glances.conf index 225700fa..0686b528 100755 --- a/docker-compose/glances.conf +++ b/docker-compose/glances.conf @@ -354,6 +354,8 @@ temperature_hdd_critical=60 battery_careful=80 battery_warning=90 battery_critical=95 +# Fan speed threashold in RPM +#fan_speed_careful=100 # Sensors alias #alias=core 0:CPU Core 0,core 1:CPU Core 1 diff --git a/glances/plugins/plugin/model.py b/glances/plugins/plugin/model.py index 247d4cd8..99539e1b 100644 --- a/glances/plugins/plugin/model.py +++ b/glances/plugins/plugin/model.py @@ -694,19 +694,32 @@ class GlancesPluginModel(object): stat_name = self.get_stat_name(header=header) # Manage limits - # If is_max is set then display the value in MAX + # If is_max is set then default style is set to MAX else default is set to OK ret = 'MAX' if is_max else 'OK' + + # Iter through limits try: - if value >= self.get_limit('critical', stat_name=stat_name): - ret = 'CRITICAL' - elif value >= self.get_limit('warning', stat_name=stat_name): - ret = 'WARNING' - elif value >= self.get_limit('careful', stat_name=stat_name): - ret = 'CAREFUL' - elif current < minimum: - ret = 'CAREFUL' + limit = self.get_limit('critical', stat_name=stat_name) except KeyError: - return 'DEFAULT' + try: + limit = self.get_limit('warning', stat_name=stat_name) + except KeyError: + try: + limit = self.get_limit('careful', stat_name=stat_name) + except KeyError: + return 'DEFAULT' + else: + if value >= limit: + ret = 'CAREFUL' + else: + if value >= limit: + ret = 'WARNING' + else: + if value >= limit: + ret = 'CRITICAL' + + if current < minimum: + ret = 'CAREFUL' # Manage log log_str = "" @@ -792,17 +805,13 @@ class GlancesPluginModel(object): # Get the limit for stat + header # Example: network_wlan0_rx_careful - try: - limit = self._limits[stat_name + '_' + criticality] - except KeyError: - # Try fallback to plugin default limit - # Example: network_careful - limit = self._limits[self.plugin_name + '_' + criticality] - - # logger.debug("{} {} value is {}".format(stat_name, criticality, limit)) + if stat_name + '_' + criticality in self._limits: + return self._limits[stat_name + '_' + criticality] + elif self.plugin_name + '_' + criticality in self._limits: + return self._limits[self.plugin_name + '_' + criticality] - # Return the limiter - return limit + # No key found, the raise an error + raise KeyError def get_limit_action(self, criticality, stat_name=""): """Return the tuple (action, repeat) for the alert. @@ -830,19 +839,12 @@ class GlancesPluginModel(object): """Return the log tag for the alert.""" # Get the log tag for stat + header # Example: network_wlan0_rx_log - try: - log_tag = self._limits[stat_name + '_log'] - except KeyError: - # Try fallback to plugin default log - # Example: network_log - try: - log_tag = self._limits[self.plugin_name + '_log'] - except KeyError: - # By default, log are disabled - return default_action - - # Return the action list - return log_tag[0].lower() == 'true' + if stat_name + '_log' in self._limits: + return self._limits[stat_name + '_log'][0].lower() == 'true' + elif self.plugin_name + '_log' in self._limits: + return self._limits[self.plugin_name + '_log'][0].lower() == 'true' + else: + return default_action def get_conf_value(self, value, header="", plugin_name=None, default=[]): """Return the configuration (header_) value for the current plugin. diff --git a/glances/plugins/sensors/__init__.py b/glances/plugins/sensors/__init__.py index 1c90b601..0ed9341a 100644 --- a/glances/plugins/sensors/__init__.py +++ b/glances/plugins/sensors/__init__.py @@ -236,9 +236,9 @@ class PluginModel(GlancesPluginModel): continue # Alert processing if i['type'] == SENSOR_TEMP_TYPE: - if self.is_limit('critical', stat_name='sensors_temperature_' + i['label']): + if self.is_limit('critical', stat_name=SENSOR_TEMP_TYPE + '_' + i['label']): # By default use the thresholds configured in the glances.conf file (see #2058) - alert = self.get_alert(current=i['value'], header='temperature_' + i['label']) + alert = self.get_alert(current=i['value'], header=SENSOR_TEMP_TYPE + '_' + i['label']) else: # Else use the system thresholds if i['critical'] is None: @@ -251,7 +251,8 @@ class PluginModel(GlancesPluginModel): alert = 'WARNING' else: alert = 'OK' - elif i['type'] == 'battery': + elif i['type'] == SENSORS_BATTERY_TYPE: + # Battery is in % alert = self.get_alert(current=100 - i['value'], header=i['type']) else: alert = self.get_alert(current=i['value'], header=i['type']) |