mirror of
https://github.com/nicolargo/glances.git
synced 2024-08-17 00:10:48 +03:00
Allow user to define only careful limits
This commit is contained in:
parent
ada7f248ba
commit
893c1452a3
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]
|
||||
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]
|
||||
|
||||
# logger.debug("{} {} value is {}".format(stat_name, criticality, limit))
|
||||
|
||||
# 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.
|
||||
|
@ -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'])
|
||||
|
Loading…
Reference in New Issue
Block a user