mirror of
https://github.com/nicolargo/glances.git
synced 2026-03-15 20:38:17 -04:00
Some field name are incorrect in CSV export #1372 and Prohibit some plug-in data from being exported to influxdb #1368
This commit is contained in:
2
NEWS
2
NEWS
@@ -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:
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user