diff options
author | nicolargo <nicolas@nicolargo.com> | 2018-12-18 09:53:18 +0100 |
---|---|---|
committer | nicolargo <nicolas@nicolargo.com> | 2018-12-18 09:53:18 +0100 |
commit | c76a5f0537a141c6f74fcffc12440fdc848cbfbd (patch) | |
tree | 9380ef0016a01293c48687d6f55dc3e5305d0c5b | |
parent | cec62a45f6b50d913a7e87447decb41856d3bdeb (diff) |
Some field name are incorrect in CSV export #1372 and Prohibit some plug-in data from being exported to influxdb #1368
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | glances/exports/glances_csv.py | 34 | ||||
-rw-r--r-- | glances/exports/glances_export.py | 46 | ||||
-rw-r--r-- | glances/stats.py | 6 |
4 files changed, 53 insertions, 35 deletions
@@ -10,6 +10,7 @@ Enhancements and new features: * Add a CSV output format to the STDOUT output mode #1363 * 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 Bugs corrected: @@ -21,6 +22,7 @@ Bugs corrected: * ERROR -- Can not grab extended stats (invalid attr name 'num_fds') #1351 * Action on port/web plugins is not working #1358 * Support for monochrome (serial) terminals e.g. vt220 #1362 + * Some field name are incorrect in CSV export #1372 Others: diff --git a/glances/exports/glances_csv.py b/glances/exports/glances_csv.py index 7df52977..bdfba95d 100644 --- a/glances/exports/glances_csv.py +++ b/glances/exports/glances_csv.py @@ -64,33 +64,31 @@ class Export(GlancesExport): def update(self, stats): """Update stats in the CSV output file.""" # Get the stats - all_stats = stats.getAllExports() - plugins = stats.getPluginsList() + all_stats = stats.getAllExportsAsDict(plugin_list=self.plugins_to_export()) # Init data with timestamp (issue#708) if self.first_line: csv_header = ['timestamp'] csv_data = [time.strftime('%Y-%m-%d %H:%M:%S')] - # Loop over available plugin - for i, plugin in enumerate(plugins): - if plugin in self.plugins_to_export(): - if isinstance(all_stats[i], list): - for stat in all_stats[i]: - # First line: header - if self.first_line: - csv_header += ('{}_{}_{}'.format( - plugin, self.get_item_key(stat), item) for item in stat) - # Others lines: stats - csv_data += itervalues(stat) - elif isinstance(all_stats[i], dict): + # Loop over plugins to export + for plugin in self.plugins_to_export(): + if isinstance(all_stats[plugin], list): + for stat in all_stats[plugin]: # First line: header if self.first_line: - fieldnames = iterkeys(all_stats[i]) - csv_header += ('{}_{}'.format(plugin, fieldname) - for fieldname in fieldnames) + csv_header += ('{}_{}_{}'.format( + plugin, self.get_item_key(stat), item) for item in stat) # Others lines: stats - csv_data += itervalues(all_stats[i]) + csv_data += itervalues(stat) + elif isinstance(all_stats[plugin], dict): + # First line: header + if self.first_line: + fieldnames = iterkeys(all_stats[plugin]) + csv_header += ('{}_{}'.format(plugin, fieldname) + for fieldname in fieldnames) + # Others lines: stats + csv_data += itervalues(all_stats[plugin]) # Export to CSV if self.first_line: diff --git a/glances/exports/glances_export.py b/glances/exports/glances_export.py index 751a9959..d660a1d9 100644 --- a/glances/exports/glances_export.py +++ b/glances/exports/glances_export.py @@ -33,6 +33,24 @@ class GlancesExport(object): """Main class for Glances export IF.""" + # For the moment, only thoses plugins can be exported + # @TODO: remove this part and make all plugins exportable + exportable_plugins = ['cpu', + 'percpu', + 'load', + 'mem', + 'memswap', + 'network', + 'diskio', + 'fs', + 'processcount', + 'ip', + 'system', + 'uptime', + 'sensors', + 'docker', + 'gpu'] + def __init__(self, config=None, args=None): """Init the export class.""" # Export name (= module name without glances_) @@ -51,27 +69,23 @@ 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() + def exit(self): """Close the export module.""" logger.debug("Finalise export interface %s" % self.export_name) - def plugins_to_export(self): + def _plugins_to_export(self): """Return the list of plugins to export.""" - return ['cpu', - 'percpu', - 'load', - 'mem', - 'memswap', - 'network', - 'diskio', - 'fs', - 'processcount', - 'ip', - 'system', - 'uptime', - 'sensors', - 'docker', - 'gpu'] + 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. diff --git a/glances/stats.py b/glances/stats.py index 48ad495d..32993b95 100644 --- a/glances/stats.py +++ b/glances/stats.py @@ -248,11 +248,15 @@ class GlancesStats(object): """Return all the stats (dict).""" return {p: self._plugins[p].get_raw() for p in self._plugins} - def getAllExports(self): + def getAllExports(self, plugin_list=None): """ Return all the stats to be exported (list). Default behavor is to export all the stat + 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 return [self._plugins[p].get_export() for p in self._plugins] def getAllExportsAsDict(self, plugin_list=None): |