mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-06 01:35:47 +03:00
Config to disable all plugins by default (or enable an exclusive list) #2089
This commit is contained in:
parent
2fb2403405
commit
d5efb63591
762
docs/api.rst
762
docs/api.rst
File diff suppressed because it is too large
Load Diff
@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
|
||||
..
|
||||
.TH "GLANCES" "1" "Jul 10, 2022" "3.2.7_beta01" "Glances"
|
||||
.TH "GLANCES" "1" "Jul 24, 2022" "3.2.7_beta01" "Glances"
|
||||
.SH NAME
|
||||
glances \- An eye on your system
|
||||
.SH SYNOPSIS
|
||||
|
@ -82,11 +82,15 @@ Examples of use:
|
||||
Display CSV stats to stdout (all stats in one line):
|
||||
$ glances --stdout-csv now,cpu.user,mem.used,load
|
||||
|
||||
Enable some plugins disabled by default (comma separated list):
|
||||
$ glances --enable-plugin sensors
|
||||
|
||||
Disable some plugins (comma separated list):
|
||||
$ glances --disable-plugin network,ports
|
||||
|
||||
Enable some plugins (comma separated list):
|
||||
$ glances --enable-plugin sensors
|
||||
Disable all plugins except some (comma separated list):
|
||||
$ glances --disable-plugin all --enable-plugin cpu,mem,load
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
@ -116,10 +120,16 @@ Examples of use:
|
||||
help='display modules (plugins & exports) list and exit',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--disable-plugin', '--disable-plugins', dest='disable_plugin', help='disable plugin (comma separed list)'
|
||||
'--disable-plugin',
|
||||
'--disable-plugins',
|
||||
dest='disable_plugin',
|
||||
help='disable plugin (comma separed list or all). If all is used, then you need to configure --enable-plugin.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--enable-plugin', '--enable-plugins', dest='enable_plugin', help='enable plugin (comma separed list)'
|
||||
'--enable-plugin',
|
||||
'--enable-plugins',
|
||||
dest='enable_plugin',
|
||||
help='enable plugin (comma separed list)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--disable-process',
|
||||
@ -552,6 +562,12 @@ Examples of use:
|
||||
disable(args, s)
|
||||
logger.debug('{} disabled by the configuration file'.format(s))
|
||||
# The configuration key can be overwrite from the command line
|
||||
if args and args.disable_plugin and 'all' in args.disable_plugin.split(','):
|
||||
if not args.enable_plugin:
|
||||
logger.critical("'all' key in --disable-plugin needs to be used with --enable-plugin")
|
||||
sys.exit(2)
|
||||
else:
|
||||
logger.info("'all' key in --disable-plugin, only plugins defined with --enable-plugin will be available")
|
||||
if args.disable_plugin is not None:
|
||||
for p in args.disable_plugin.split(','):
|
||||
disable(args, p)
|
||||
|
@ -165,6 +165,10 @@ class Plugin(GlancesPlugin):
|
||||
# Init the return message
|
||||
ret = []
|
||||
|
||||
# Only process if stats exist and plugin not disabled
|
||||
if not self.stats or self.is_disabled():
|
||||
return ret
|
||||
|
||||
# Build the string message
|
||||
if args.client:
|
||||
# Client mode
|
||||
|
@ -76,4 +76,13 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
def msg_curse(self, args=None, max_width=None):
|
||||
"""Return the string to display in the curse interface."""
|
||||
return [self.curse_add_line('Uptime: {}'.format(self.stats))]
|
||||
# Init the return message
|
||||
ret = []
|
||||
|
||||
# Only process if stats exist and plugin not disabled
|
||||
if not self.stats or self.is_disabled():
|
||||
return ret
|
||||
|
||||
ret = [self.curse_add_line('Uptime: {}'.format(self.stats))]
|
||||
|
||||
return ret
|
||||
|
@ -99,7 +99,7 @@ class GlancesStats(object):
|
||||
# generate self._plugins_list["xxx"] = ...
|
||||
name = plugin_script[len(self.header) : -3].lower()
|
||||
|
||||
# Loaf the plugin class
|
||||
# Load the plugin class
|
||||
try:
|
||||
# Import the plugin
|
||||
plugin = __import__(plugin_script[:-3])
|
||||
@ -110,13 +110,18 @@ class GlancesStats(object):
|
||||
# on the console but do not crash
|
||||
logger.critical("Error while initializing the {} plugin ({})".format(name, e))
|
||||
logger.error(traceback.format_exc())
|
||||
# Disable the plugin
|
||||
# An error occure, disable the plugin
|
||||
if args is not None:
|
||||
setattr(args, 'disable_' + name, False)
|
||||
else:
|
||||
# Set the disable_<name> to False by default
|
||||
# Manage the default status of the plugin (enable or disable)
|
||||
if args is not None:
|
||||
setattr(args, 'disable_' + name, getattr(args, 'disable_' + name, False))
|
||||
# If the all key is set in the disable_plugin option then look in the enable_plugin option
|
||||
if getattr(args, 'disable_all', False):
|
||||
logger.info('%s => %s', name, getattr(args, 'enable_' + name, False))
|
||||
setattr(args, 'disable_' + name, not getattr(args, 'enable_' + name, False))
|
||||
else:
|
||||
setattr(args, 'disable_' + name, getattr(args, 'disable_' + name, False))
|
||||
|
||||
def load_plugins(self, args=None):
|
||||
"""Load all plugins in the 'plugins' folder."""
|
||||
|
Loading…
Reference in New Issue
Block a user