From 7273343a3ed78ab88e9b15416894605b195f2ebe Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Sun, 11 Jan 2015 16:03:16 +0100 Subject: [PATCH] User can force log/alert using the configuration file (issue #437) --- NEWS | 1 + conf/glances-test.conf | 7 ++++++- conf/glances.conf | 6 ++++++ docs/glances-doc.rst | 28 +++++++++++++++++++++++++++ glances/plugins/glances_cpu.py | 2 +- glances/plugins/glances_plugin.py | 32 +++++++++++++++++++++++++------ 6 files changed, 68 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 6480042c..ff3fc4b7 100644 --- a/NEWS +++ b/NEWS @@ -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: diff --git a/conf/glances-test.conf b/conf/glances-test.conf index 4a804eea..e850a0f5 100644 --- a/conf/glances-test.conf +++ b/conf/glances-test.conf @@ -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) diff --git a/conf/glances.conf b/conf/glances.conf index f3df2a25..e42123a5 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -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) diff --git a/docs/glances-doc.rst b/docs/glances-doc.rst index 0f33a063..846c4da3 100644 --- a/docs/glances-doc.rst +++ b/docs/glances-doc.rst @@ -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 =================== diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 8db1167d..58e70361 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -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 = [] diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index f7de80eb..ae8f81cd 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -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)"""