diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | README.rst | 23 | ||||
-rw-r--r-- | docs/quickstart.rst | 10 | ||||
-rw-r--r-- | glances/outputs/glances_stdout_csv.py | 16 |
4 files changed, 43 insertions, 7 deletions
@@ -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 diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 725863a9..c7c212f8 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -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 diff --git a/glances/outputs/glances_stdout_csv.py b/glances/outputs/glances_stdout_csv.py index 278c1a45..8280c5f3 100644 --- a/glances/outputs/glances_stdout_csv.py +++ b/glances/outputs/glances_stdout_csv.py @@ -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) |