提交 4458ac97 编写于 作者: N nicolargo

Export uptime to CSV (issue #890)

上级 80cc297a
......@@ -68,7 +68,8 @@ class Export(GlancesExport):
plugins = stats.getAllPlugins()
# Init data with timestamp (issue#708)
csv_header = ['timestamp']
if self.first_line:
csv_header = ['timestamp']
csv_data = [time.strftime('%Y-%m-%d %H:%M:%S')]
# Loop over available plugin
......@@ -90,6 +91,12 @@ class Export(GlancesExport):
for fieldname in fieldnames)
# Others lines: stats
csv_data += itervalues(all_stats[i])
elif isinstance(all_stats[i], (int, float, str)):
# First line: header
if self.first_line:
csv_header.append(str(plugin))
# Others lines: stats
csv_data.append(str(all_stats[i]))
# Export to CSV
if self.first_line:
......
......@@ -64,7 +64,8 @@ class GlancesExport(object):
'system',
'uptime',
'sensors',
'docker']
'docker',
'uptime']
def get_item_key(self, item):
"""Return the value of the item 'key'."""
......
......@@ -47,12 +47,20 @@ class Plugin(GlancesPlugin):
self.align = 'right'
# Init the stats
self.uptime = datetime.now()
self.reset()
def reset(self):
"""Reset/init the stats."""
self.stats = {}
def get_export(self):
"""Overwrite the default export method.
Export uptime in seconds.
"""
return self.uptime.seconds
@GlancesPlugin._check_decorator
@GlancesPlugin._log_result_decorator
def update(self):
......@@ -62,10 +70,10 @@ class Plugin(GlancesPlugin):
if self.input_method == 'local':
# Update stats using the standard system lib
uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time())
self.uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time())
# Convert uptime to string (because datetime is not JSONifi)
self.stats = str(uptime).split('.')[0]
self.stats = str(self.uptime).split('.')[0]
elif self.input_method == 'snmp':
# Update stats using SNMP
uptime = self.get_stats_snmp(snmp_oid=snmp_oid)['_uptime']
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册