mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-03 15:15:02 +03:00
Add support for the --modules-list
This commit is contained in:
parent
62efccb852
commit
13e4652bf1
@ -65,7 +65,7 @@ class Export(GlancesExport):
|
||||
"""Update stats in the CSV output file."""
|
||||
# Get the stats
|
||||
all_stats = stats.getAllExports()
|
||||
plugins = stats.getAllPlugins()
|
||||
plugins = stats.getPluginsList()
|
||||
|
||||
# Init data with timestamp (issue#708)
|
||||
if self.first_line:
|
||||
|
@ -54,7 +54,7 @@ class GlancesGraph(object):
|
||||
"""Reset all the history."""
|
||||
if not self.graph_enabled():
|
||||
return False
|
||||
for p in stats.getAllPlugins():
|
||||
for p in stats.getPluginsList():
|
||||
h = stats.get_plugin(p).get_stats_history()
|
||||
if h is not None:
|
||||
stats.get_plugin(p).reset_stats_history()
|
||||
@ -94,7 +94,7 @@ class GlancesGraph(object):
|
||||
return 0
|
||||
|
||||
index_all = 0
|
||||
for p in stats.getAllPlugins():
|
||||
for p in stats.getPluginsList():
|
||||
# History
|
||||
h = stats.get_plugin(p).get_export_history()
|
||||
# Current plugin item history list
|
||||
|
@ -114,6 +114,10 @@ Examples of use:
|
||||
parser.add_argument('-C', '--config', dest='conf_file',
|
||||
help='path to the configuration file')
|
||||
# Disable plugin
|
||||
parser.add_argument('--modules-list', '--module-list',
|
||||
action='store_true', default=False,
|
||||
dest='modules_list',
|
||||
help='display modules (plugins & exports) list and exit')
|
||||
parser.add_argument('--disable-plugin', dest='disable_plugin',
|
||||
help='disable plugin (comma separed list)')
|
||||
parser.add_argument('--disable-process', action='store_true', default=False,
|
||||
|
@ -168,7 +168,7 @@ class GlancesBottle(object):
|
||||
self.stats = stats
|
||||
|
||||
# Init plugin list
|
||||
self.plugins_list = self.stats.getAllPlugins()
|
||||
self.plugins_list = self.stats.getPluginsList()
|
||||
|
||||
# Bind the Bottle TCP address/port
|
||||
if self.args.open_web_browser:
|
||||
|
@ -494,7 +494,7 @@ class _GlancesCurses(object):
|
||||
"""
|
||||
ret = {}
|
||||
|
||||
for p in stats.getAllPlugins(enable=False):
|
||||
for p in stats.getPluginsList(enable=False):
|
||||
if p == 'quicklook' or p == 'processlist':
|
||||
# processlist is done later
|
||||
# because we need to know how many processes could be displayed
|
||||
|
@ -162,7 +162,7 @@ class GlancesInstance(object):
|
||||
|
||||
def getAllPlugins(self):
|
||||
# Return the plugins list
|
||||
return json.dumps(self.stats.getAllPlugins())
|
||||
return json.dumps(self.stats.getPluginsList())
|
||||
|
||||
def getAllLimits(self):
|
||||
# Return all the plugins limits
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
"""Manage the Glances standalone session."""
|
||||
|
||||
import sys
|
||||
|
||||
from glances.globals import WINDOWS
|
||||
from glances.logger import logger
|
||||
@ -41,6 +42,12 @@ class GlancesStandalone(object):
|
||||
# Init stats
|
||||
self.stats = GlancesStats(config=config, args=args)
|
||||
|
||||
# Modules (plugins and exporters) are loaded at this point
|
||||
# Glances can display the list if asked...
|
||||
if args.modules_list:
|
||||
self.display_modules_list()
|
||||
sys.exit(0)
|
||||
|
||||
# If process extended stats is disabled by user
|
||||
if not args.enable_process_extended:
|
||||
logger.debug("Extended stats for top process are disabled")
|
||||
@ -85,6 +92,13 @@ class GlancesStandalone(object):
|
||||
def quiet(self):
|
||||
return self._quiet
|
||||
|
||||
def display_modules_list(self):
|
||||
"""Display modules list"""
|
||||
print("Plugins list: {}".format(
|
||||
', '.join(sorted(self.stats.getPluginsList(enable=False)))))
|
||||
print("Exporters list: {}".format(
|
||||
', '.join(sorted(self.stats.getExportsList(enable=False)))))
|
||||
|
||||
def __serve_forever(self):
|
||||
"""Main loop for the CLI."""
|
||||
# Start a counter used to compute the time needed for
|
||||
|
@ -87,14 +87,16 @@ class GlancesStats(object):
|
||||
"""Wrapper to load: plugins and export modules."""
|
||||
|
||||
# Init the plugins dict
|
||||
# Active plugins dictionnary
|
||||
self._plugins = collections.defaultdict(dict)
|
||||
|
||||
# Load the plugins
|
||||
self.load_plugins(args=args)
|
||||
|
||||
# Init the export modules dict
|
||||
# Active exporters dictionnary
|
||||
self._exports = collections.defaultdict(dict)
|
||||
|
||||
# All available exporters dictionnary
|
||||
self._exports_all = collections.defaultdict(dict)
|
||||
# Load the export modules
|
||||
self.load_exports(args=args)
|
||||
|
||||
@ -102,7 +104,7 @@ class GlancesStats(object):
|
||||
sys.path = sys_path
|
||||
|
||||
def _load_plugin(self, plugin_script, args=None, config=None):
|
||||
"""Load the plugin (script), init it and add to the _plugin dict"""
|
||||
"""Load the plugin (script), init it and add to the _plugin dict."""
|
||||
# The key is the plugin name
|
||||
# for example, the file glances_xxx.py
|
||||
# generate self._plugins_list["xxx"] = ...
|
||||
@ -136,23 +138,26 @@ class GlancesStats(object):
|
||||
args=args, config=self.config)
|
||||
|
||||
# Log plugins list
|
||||
logger.debug("Available plugins list: {}".format(self.getAllPlugins()))
|
||||
logger.debug("Active plugins list: {}".format(self.getPluginsList()))
|
||||
|
||||
def load_exports(self, args=None):
|
||||
"""Load all export modules in the 'exports' folder."""
|
||||
if args is None:
|
||||
return False
|
||||
header = "glances_"
|
||||
# Transform the arguments list into a dict
|
||||
# The aim is to chec if the export module should be loaded
|
||||
# Build the export module available list
|
||||
args_var = vars(locals()['args'])
|
||||
for item in os.listdir(exports_path):
|
||||
export_name = os.path.basename(item)[len(header):-3].lower()
|
||||
if (item.startswith(header) and
|
||||
item.endswith(".py") and
|
||||
item != (header + "export.py") and
|
||||
item != (header + "history.py") and
|
||||
args_var['export_' + export_name] is not None and
|
||||
item != (header + "history.py")):
|
||||
self._exports_all[export_name] = None
|
||||
|
||||
# Aim is to check if the export module should be loaded
|
||||
for export_name in self._exports_all:
|
||||
if (args_var['export_' + export_name] is not None and
|
||||
args_var['export_' + export_name] is not False):
|
||||
# Import the export module
|
||||
export_module = __import__(os.path.basename(item)[:-3])
|
||||
@ -160,22 +165,38 @@ class GlancesStats(object):
|
||||
# The key is the module name
|
||||
# for example, the file glances_xxx.py
|
||||
# generate self._exports_list["xxx"] = ...
|
||||
self._exports[export_name] = export_module.Export(args=args, config=self.config)
|
||||
self._exports[export_name] = export_module.Export(args=args,
|
||||
config=self.config)
|
||||
self._exports_all[export_name] = self._exports[export_name]
|
||||
# Log plugins list
|
||||
logger.debug("Available exports modules list: {}".format(self.getExportList()))
|
||||
logger.debug("Active exports modules list: {}".format(self.getExportsList()))
|
||||
return True
|
||||
|
||||
def getAllPlugins(self, enable=True):
|
||||
"""Return the enable plugins list.
|
||||
if enable is False, return the list of all the plugins"""
|
||||
def getPluginsList(self, enable=True):
|
||||
"""Return the plugins list.
|
||||
|
||||
if enable is True, only return the active plugins (default)
|
||||
if enable is False, return all the plugins
|
||||
|
||||
Return: list of plugin name
|
||||
"""
|
||||
if enable:
|
||||
return [p for p in self._plugins if self._plugins[p].is_enable()]
|
||||
else:
|
||||
return [p for p in self._plugins]
|
||||
|
||||
def getExportList(self):
|
||||
"""Return the exports modules list."""
|
||||
return [e for e in self._exports]
|
||||
def getExportsList(self, enable=True):
|
||||
"""Return the export module list.
|
||||
|
||||
if enable is True, only return the active exporters (default)
|
||||
if enable is False, return all the exporters
|
||||
|
||||
Return: list of export module name
|
||||
"""
|
||||
if enable:
|
||||
return [e for e in self._exports]
|
||||
else:
|
||||
return [e for e in self._exports_all]
|
||||
|
||||
def load_limits(self, config=None):
|
||||
"""Load the stats limits (except the one in the exclude list)."""
|
||||
|
Loading…
Reference in New Issue
Block a user