提交 cd06e045 编写于 作者: N nicolargo

Add a CSV output format to the STDOUT output mode #1363

上级 e2b61d94
......@@ -7,6 +7,7 @@ Version 3.1
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
......
......@@ -358,6 +358,29 @@ network or defined in the configuration file:
$ glances --browser
You can also display raw stats on stdout:
.. code-block:: console
$ glances --stdout cpu.user,mem.used,load
cpu.user: 30.7
mem.used: 3278204928
load: {'cpucore': 4, 'min1': 0.21, 'min5': 0.4, 'min15': 0.27}
cpu.user: 3.4
mem.used: 3275251712
load: {'cpucore': 4, 'min1': 0.19, 'min5': 0.39, 'min15': 0.27}
...
or in a CSV format thanks to the stdout-csv option:
.. code-block:: console
$ glances --stdout-csv now,cpu.user,mem.used,load
now,cpu.user,mem.used,load.cpucore,load.min1,load.min5,load.min15
2018-12-08 22:04:20 CEST,7.3,5948149760,4,1.04,0.99,1.04
2018-12-08 22:04:23 CEST,5.4,5949136896,4,1.04,0.99,1.04
...
and RTFM, always.
Documentation
......
......@@ -37,6 +37,16 @@ It is also possible to display RAW JSON stats directly to stdout using:
load: {'cpucore': 4, 'min1': 0.19, 'min5': 0.39, 'min15': 0.27}
...
or in a CSV format thanks to the stdout-csv option:
.. code-block:: console
$ glances --stdout-csv now,cpu.user,mem.used,load
now,cpu.user,mem.used,load.cpucore,load.min1,load.min5,load.min15
2018-12-08 22:04:20 CEST,7.3,5948149760,4,1.04,0.99,1.04
2018-12-08 22:04:23 CEST,5.4,5949136896,4,1.04,0.99,1.04
...
Note: It will display one line per stat per refresh.
Client/Server Mode
......
......@@ -112,6 +112,7 @@ class GlancesStdoutCsv(object):
Refresh every duration second.
"""
# Build the stats list
line = ''
for plugin, attribute in self.plugins_list:
# Check if the plugin exist and is enable
if plugin in stats.getPluginsList() and \
......@@ -120,17 +121,18 @@ class GlancesStdoutCsv(object):
else:
continue
# Build the line to display (header or data)
if self.header:
line = self.build_header(plugin, attribute, stat)
# Display header one time
self.header = False
else:
line = self.build_data(plugin, attribute, stat)
# Build the line to display (header or data)
if self.header:
line += self.build_header(plugin, attribute, stat)
else:
line += self.build_data(plugin, attribute, stat)
# Display the line (without the last 'separator')
print(line[:-1])
# Display header one time
self.header = False
# Wait until next refresh
if duration > 0:
time.sleep(duration)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册