mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-23 20:45:33 +03:00
Remove the static exportable_plugins list from glances_export.py #1556"
Limiting data exported for economic storage #1443
This commit is contained in:
parent
f7260fb0d2
commit
5ce964bac3
@ -71,7 +71,7 @@ class Export(GlancesExport):
|
||||
def update(self, stats):
|
||||
"""Update stats in the CSV output file."""
|
||||
# Get the stats
|
||||
all_stats = stats.getAllExportsAsDict(plugin_list=self.plugins_to_export())
|
||||
all_stats = stats.getAllExportsAsDict(plugin_list=self.plugins_to_export(stats))
|
||||
|
||||
# Init data with timestamp (issue#708)
|
||||
if self.first_line:
|
||||
@ -79,7 +79,7 @@ class Export(GlancesExport):
|
||||
csv_data = [time.strftime('%Y-%m-%d %H:%M:%S')]
|
||||
|
||||
# Loop over plugins to export
|
||||
for plugin in self.plugins_to_export():
|
||||
for plugin in self.plugins_to_export(stats):
|
||||
if isinstance(all_stats[plugin], list):
|
||||
for stat in all_stats[plugin]:
|
||||
# First line: header
|
||||
@ -102,7 +102,7 @@ class Export(GlancesExport):
|
||||
# New file, write the header on top on the CSV file
|
||||
self.writer.writerow(csv_header)
|
||||
# File already exist, check if header are compatible
|
||||
if self.old_header != csv_header:
|
||||
if self.old_header != csv_header and self.old_header is not None:
|
||||
# Header are different, log an error and do not write data
|
||||
logger.error("Cannot append data to existing CSV file. Headers are different.")
|
||||
logger.debug("Old header: {}".format(self.old_header))
|
||||
|
@ -23,25 +23,19 @@ class GlancesExport(object):
|
||||
|
||||
"""Main class for Glances export IF."""
|
||||
|
||||
# For the moment, only the below plugins can be exported
|
||||
# List of non exportable plugins
|
||||
# @TODO: remove this part and make all plugins exportable (see issue #1556)
|
||||
# @TODO: also make this list configurable by the user (see issue #1443)
|
||||
exportable_plugins = [
|
||||
'cpu',
|
||||
'percpu',
|
||||
'load',
|
||||
'mem',
|
||||
'memswap',
|
||||
'network',
|
||||
'diskio',
|
||||
'fs',
|
||||
'processcount',
|
||||
'ip',
|
||||
'system',
|
||||
'uptime',
|
||||
'sensors',
|
||||
'docker',
|
||||
'gpu',
|
||||
non_exportable_plugins = [
|
||||
'alert',
|
||||
'amps',
|
||||
'help',
|
||||
'now',
|
||||
'plugin',
|
||||
'ports',
|
||||
'processlist',
|
||||
'psutilversion',
|
||||
'quicklook'
|
||||
]
|
||||
|
||||
def __init__(self, config=None, args=None):
|
||||
@ -62,24 +56,13 @@ class GlancesExport(object):
|
||||
self.host = None
|
||||
self.port = None
|
||||
|
||||
# Build the export list on startup to avoid change during execution
|
||||
self.export_list = self._plugins_to_export()
|
||||
# Save last export list
|
||||
self._last_exported_list = None
|
||||
|
||||
def exit(self):
|
||||
"""Close the export module."""
|
||||
logger.debug("Finalise export interface %s" % self.export_name)
|
||||
|
||||
def _plugins_to_export(self):
|
||||
"""Return the list of plugins to export."""
|
||||
ret = self.exportable_plugins
|
||||
for p in ret:
|
||||
if getattr(self.args, 'disable_' + p):
|
||||
ret.remove(p)
|
||||
return ret
|
||||
|
||||
def plugins_to_export(self):
|
||||
return self.export_list
|
||||
|
||||
def load_conf(self, section, mandatories=['host', 'port'], options=None):
|
||||
"""Load the export <section> configuration in the Glances configuration file.
|
||||
|
||||
@ -145,6 +128,18 @@ class GlancesExport(object):
|
||||
|
||||
return d_tags
|
||||
|
||||
def plugins_to_export(self, stats):
|
||||
"""Return the list of plugins to export.
|
||||
|
||||
:param stats: the stats object
|
||||
:return: a list of plugins to export
|
||||
"""
|
||||
return [p for p in stats.getPluginsList() if p not in self.non_exportable_plugins]
|
||||
|
||||
def last_exported_list(self):
|
||||
"""Return the list of plugins last exported."""
|
||||
return self._last_exported_list
|
||||
|
||||
def update(self, stats):
|
||||
"""Update stats to a server.
|
||||
|
||||
@ -156,11 +151,12 @@ class GlancesExport(object):
|
||||
return False
|
||||
|
||||
# Get all the stats & limits
|
||||
all_stats = stats.getAllExportsAsDict(plugin_list=self.plugins_to_export())
|
||||
all_limits = stats.getAllLimitsAsDict(plugin_list=self.plugins_to_export())
|
||||
self._last_exported_list = self.plugins_to_export(stats)
|
||||
all_stats = stats.getAllExportsAsDict(plugin_list=self.last_exported_list())
|
||||
all_limits = stats.getAllLimitsAsDict(plugin_list=self.last_exported_list())
|
||||
|
||||
# Loop over plugins to export
|
||||
for plugin in self.plugins_to_export():
|
||||
for plugin in self.last_exported_list():
|
||||
if isinstance(all_stats[plugin], dict):
|
||||
all_stats[plugin].update(all_limits[plugin])
|
||||
elif isinstance(all_stats[plugin], list):
|
||||
|
@ -81,7 +81,7 @@ class Export(GlancesExport):
|
||||
plugins = stats.getPluginsList()
|
||||
for plugin_name in plugins:
|
||||
plugin = stats._plugins[plugin_name]
|
||||
if plugin_name in self.plugins_to_export():
|
||||
if plugin_name in self.plugins_to_export(stats):
|
||||
self.export(plugin_name, plugin.get_export_history())
|
||||
|
||||
logger.info("Graphs created in the folder {}".format(self.path))
|
||||
|
@ -47,7 +47,7 @@ class Export(GlancesExport):
|
||||
"""Export the stats to the JSON file."""
|
||||
|
||||
# Check for completion of loop for all exports
|
||||
if name == self.plugins_to_export()[0] and self.buffer != {}:
|
||||
if name == self.last_exported_list()[0] and self.buffer != {}:
|
||||
# One whole loop has been completed
|
||||
# Flush stats to file
|
||||
logger.debug("Exporting stats ({}) to JSON file ({})".format(listkeys(self.buffer), self.json_filename))
|
||||
|
@ -54,7 +54,7 @@ class Export(GlancesExport):
|
||||
|
||||
def export(self, name, columns, points):
|
||||
"""Export the stats to the Statsd server."""
|
||||
if name == self.plugins_to_export()[0] and self.buffer != {}:
|
||||
if name == self.last_exported_list()[0] and self.buffer != {}:
|
||||
# One complete loop have been done
|
||||
logger.debug("Export stats ({}) to RESTful endpoint ({})".format(listkeys(self.buffer), self.client))
|
||||
# Export stats
|
||||
|
@ -97,7 +97,7 @@ class GlancesStats(object):
|
||||
# The key is the plugin name
|
||||
# for example, the file glances_xxx.py
|
||||
# generate self._plugins_list["xxx"] = ...
|
||||
name = plugin_script[len(self.header) : -3].lower()
|
||||
name = plugin_script[len(self.header):-3].lower()
|
||||
|
||||
# Load the plugin class
|
||||
try:
|
||||
@ -253,8 +253,8 @@ class GlancesStats(object):
|
||||
if plugin_list is provided, only export stats of given plugin (list)
|
||||
"""
|
||||
if plugin_list is None:
|
||||
# All plugins should be exported
|
||||
plugin_list = self._plugins
|
||||
# All enabled plugins should be exported
|
||||
plugin_list = self.getPluginsList()
|
||||
return [self._plugins[p].get_export() for p in self._plugins]
|
||||
|
||||
def getAllExportsAsDict(self, plugin_list=None):
|
||||
@ -264,13 +264,20 @@ class GlancesStats(object):
|
||||
if plugin_list is provided, only export stats of given plugin (list)
|
||||
"""
|
||||
if plugin_list is None:
|
||||
# All plugins should be exported
|
||||
plugin_list = self._plugins
|
||||
# All enabled plugins should be exported
|
||||
plugin_list = self.getPluginsList()
|
||||
return {p: self._plugins[p].get_export() for p in plugin_list}
|
||||
|
||||
def getAllLimits(self):
|
||||
"""Return the plugins limits list."""
|
||||
return [self._plugins[p].limits for p in self._plugins]
|
||||
def getAllLimits(self, plugin_list=None):
|
||||
"""Return the plugins limits list.
|
||||
|
||||
Default behavior is to export all the limits
|
||||
if plugin_list is provided, only export limits of given plugin (list)
|
||||
"""
|
||||
if plugin_list is None:
|
||||
# All enabled plugins should be exported
|
||||
plugin_list = self.getPluginsList()
|
||||
return [self._plugins[p].limits for p in plugin_list]
|
||||
|
||||
def getAllLimitsAsDict(self, plugin_list=None):
|
||||
"""Return all the stats limits (dict).
|
||||
@ -279,8 +286,8 @@ class GlancesStats(object):
|
||||
if plugin_list is provided, only export limits of given plugin (list)
|
||||
"""
|
||||
if plugin_list is None:
|
||||
# All plugins should be exported
|
||||
plugin_list = self._plugins
|
||||
# All enabled plugins should be exported
|
||||
plugin_list = self.getPluginsList()
|
||||
return {p: self._plugins[p].limits for p in plugin_list}
|
||||
|
||||
def getAllViews(self):
|
||||
|
Loading…
Reference in New Issue
Block a user