From ab5e7247d3d59c92c9f9ed489903c1311caf321d Mon Sep 17 00:00:00 2001 From: nicolargo Date: Thu, 27 Dec 2018 09:58:21 +0100 Subject: [PATCH] Disable plugin from Glances configuration file #1378 --- NEWS | 3 ++- conf/glances.conf | 6 +++++- docs/config.rst | 1 + glances/config.py | 9 ++++++++- glances/main.py | 7 +++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index e891c944..def7673d 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ Enhancements and new features: * Feature request: HDD S.M.A.R.T. reports (thanks to @tnibert) #1288 * Sort docker stats #1276 * Prohibit some plug-in data from being exported to influxdb #1368 + * Disable plugin from Glances configuration file #1378 Bugs corrected: @@ -24,7 +25,7 @@ Bugs corrected: * Support for monochrome (serial) terminals e.g. vt220 #1362 * TypeError on opening (Wifi plugin) #1373 * Some field name are incorrect in CSV export #1372 - * Standard output misbehaviour (need to flush) #1376 + * Standard output misbehaviour (need to flush) #1376 Others: diff --git a/conf/glances.conf b/conf/glances.conf index 78564ce9..bf5c50de 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -24,6 +24,9 @@ max_processes_display=30 ############################################################################## [quicklook] +# Set to true to disable a plugin +# Note: you can also disable it from the command line (see --disable-plugin) +disable=false # Define CPU, MEM and SWAP thresholds in % cpu_careful=50 cpu_warning=70 @@ -36,6 +39,7 @@ swap_warning=70 swap_critical=90 [cpu] +disable=False # Default values if not defined: 50/70/90 (except for iowait) user_careful=50 user_warning=70 @@ -151,7 +155,7 @@ hide=loop.* [fs] # Define the list of hidden file system (comma-separated regexp) -#hide=/boot.* +hide=/boot.*,/snap.* # Define filesystem space thresholds in % # Default values if not defined: 50/70/90 # It is also possible to define per mount point value diff --git a/docs/config.rst b/docs/config.rst index 54264e63..60edfbfe 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -48,6 +48,7 @@ have a section. Below an example for the CPU plugin: .. code-block:: ini [cpu] + disable=false user_careful=50 user_warning=70 user_critical=90 diff --git a/glances/config.py b/glances/config.py index 68f7755d..c0652921 100644 --- a/glances/config.py +++ b/glances/config.py @@ -272,7 +272,7 @@ class Config(object): default=None): """Get the value of an option, if it exists. - If it did not exist, then return de default value. + If it did not exist, then return the default value. It allows user to define dynamic configuration key (see issue#1204) Dynamic vlaue should starts and end with the ` char @@ -307,3 +307,10 @@ class Config(object): return self.parser.getfloat(section, option) except NoOptionError: return float(default) + + def get_bool_value(self, section, option, default=True): + """Get the bool value of an option, if it exists.""" + try: + return self.parser.getboolean(section, option) + except NoOptionError: + return bool(default) diff --git a/glances/main.py b/glances/main.py index 6678af56..2432f0c5 100644 --- a/glances/main.py +++ b/glances/main.py @@ -264,6 +264,13 @@ Examples of use: if args.disable_plugin is not None: for p in args.disable_plugin.split(','): disable(args, p) + else: + # Allow users to disable plugins from the glances.conf (issue #1378) + for s in self.config.sections(): + if self.config.has_section(s) \ + and (self.config.get_bool_value(s, 'disable', False)): + disable(args, s) + logger.debug('{} disabled by the configuration file'.format(s)) # Exporters activation if args.export is not None: