User can force log/alert using the configuration file (issue #437)

This commit is contained in:
Nicolargo 2015-01-11 16:03:16 +01:00
parent 4107fcf3fd
commit 7273343a3e
6 changed files with 68 additions and 8 deletions

1
NEWS
View File

@ -14,6 +14,7 @@ Enhancements and news features:
* The Web inteface is now based on BootStarp / RWD grid (issue #417, #366 and #461) Thanks to Nicolas Hart @nclsHart
* Add the RAID plugin (issue #447)
* Add the Docker plugin (issue #440)
* It is possible to define (through teh configuration file) if an alarm should be logged or not (using the _log option) (issue #437)
Bugs corrected:

View File

@ -3,6 +3,7 @@
user_careful=50
user_warning=70
user_critical=90
#user_log=False
user_critical_action=echo {{user}} {{value}} {{max}} > /tmp/cpu.alert
iowait_careful=50
iowait_warning=70
@ -13,6 +14,7 @@ system_critical=90
steal_careful=50
steal_warning=70
steal_critical=90
#steal_log=True
[percpu]
# Default values if not defined: 50/70/90
@ -34,6 +36,7 @@ system_critical=90
careful=0.7
warning=1.0
critical=5.0
#log=False
[mem]
# Default limits for free RAM memory in %
@ -53,14 +56,16 @@ critical=90
# Define the list of hidden network interfaces (comma separeted)
hide=lo
# WLAN0 alias name
wlan0_alias=Wireless
#wlan0_alias=Wireless
# WLAN0 Default limits (in bits per second aka bps) for interface bitrate
wlan0_rx_careful=4000000
wlan0_rx_warning=5000000
wlan0_rx_critical=6000000
wlan0_rx_log=True
wlan0_tx_careful=700000
wlan0_tx_warning=900000
wlan0_tx_critical=1000000
wlan0_tx_log=True
[diskio]
# Define the list of hidden disks (comma separeted)

View File

@ -3,6 +3,8 @@
user_careful=50
user_warning=70
user_critical=90
#user_log=False
#user_critical_action=echo {{user}} {{value}} {{max}} > /tmp/cpu.alert
iowait_careful=50
iowait_warning=70
iowait_critical=90
@ -12,6 +14,7 @@ system_critical=90
steal_careful=50
steal_warning=70
steal_critical=90
#steal_log=True
[percpu]
# Default values if not defined: 50/70/90
@ -33,6 +36,7 @@ system_critical=90
careful=0.7
warning=1.0
critical=5.0
#log=False
[mem]
# Default limits for free RAM memory in %
@ -57,9 +61,11 @@ critical=90
#wlan0_rx_careful=4000000
#wlan0_rx_warning=5000000
#wlan0_rx_critical=6000000
#wlan0_rx_log=True
#wlan0_tx_careful=700000
#wlan0_tx_warning=900000
#wlan0_tx_critical=1000000
#wlan0_tx_log=True
#[diskio]
# Define the list of hidden disks (comma separeted)

View File

@ -320,6 +320,34 @@ e.g., on Linux:
On OS X, you should copy the configuration file to
``~/Library/Application Support/glances/``.
*Configuration file description*
Each plugin and export module can have a section.
Example for the CPU plugin:
.. code-block::
[cpu]
user_careful=50
user_warning=70
user_critical=90
iowait_careful=50
iowait_warning=70
iowait_critical=90
system_careful=50
system_warning=70
system_critical=90
steal_careful=50
steal_warning=70
steal_critical=90
By default Steal CPU time alerts aren't logged. If you want to enable log/alert, just add:
.. code-block::
steal_log=True
Logs and debug mode
===================

View File

@ -131,7 +131,7 @@ class Plugin(GlancesPlugin):
return self.stats
def msg_curse(self, args=None):
"""Return the list to display in the curse interface."""
"""Return the list to display in the UI"""
# Init the return message
ret = []

View File

@ -292,7 +292,9 @@ class GlancesPlugin(object):
If defined 'header' is added between the plugin name and the status.
Only useful for stats with several alert status.
If log=True than return the logged status.
If log=True than add log if necessary
elif log=False than do not log
elig log=None than apply the config given in the conf file
"""
# Compute the %
try:
@ -324,7 +326,7 @@ class GlancesPlugin(object):
# Manage log
log_str = ""
if log:
if self.__get_limit_log(stat_name=stat_name, default_action=log):
# Add _LOG to the return string
# So stats will be highlited with a specific color
log_str = "_LOG"
@ -376,17 +378,35 @@ class GlancesPlugin(object):
def __get_limit_action(self, criticity, stat_name=""):
"""Return the action for the alert"""
# Get the limit for stat + header
# Get the action for stat + header
# Exemple: network_wlan0_rx_careful_action
try:
action = self.limits[stat_name + '_' + criticity + '_action']
ret = self.limits[stat_name + '_' + criticity + '_action']
except KeyError:
# Try fallback to plugin default limit
# Exemple: network_careful_action
action = self.limits[self.plugin_name + '_' + criticity + '_action']
ret = self.limits[self.plugin_name + '_' + criticity + '_action']
# Return the action list
return action
return ret
def __get_limit_log(self, stat_name, default_action=False):
"""Return the log tag for the alert"""
# Get the log tag for stat + header
# Exemple: network_wlan0_rx_log
try:
log_tag = self.limits[stat_name + '_log']
except KeyError:
# Try fallback to plugin default log
# Exemple: network_log
try:
log_tag = self.limits[self.plugin_name + '_log']
except KeyError:
# By defaukt, log are disabled
return default_action
# Return the action list
return log_tag[0].lower() == 'true'
def get_conf_value(self, value, header="", plugin_name=None):
"""Return the configuration (header_) value for the current plugin (or the one given by the plugin_name var)"""