Disable plugin from Glances configuration file #1378

This commit is contained in:
nicolargo 2018-12-27 09:58:21 +01:00
parent 28fa73cdff
commit ab5e7247d3
5 changed files with 23 additions and 3 deletions

3
NEWS
View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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: