From 9af0cb5431d626744cb61371e80e0ec9b94ed2b5 Mon Sep 17 00:00:00 2001 From: Nicolas Hennion Date: Mon, 30 Dec 2013 16:45:45 +0100 Subject: [PATCH] Add CPU stats to the CSV output --- docs/glances-doc.rst | 23 +++++++++++++++++++++++ glances/glances.py | 8 ++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/glances-doc.rst b/docs/glances-doc.rst index af533c55..99ac4360 100644 --- a/docs/glances-doc.rst +++ b/docs/glances-doc.rst @@ -518,6 +518,7 @@ else: On the left, you can easily see if you are connected to a Glances server. + API documentation ================= @@ -525,6 +526,28 @@ Glances uses a `XML-RPC server`_ and can be used by another client software. API documentation is available at https://github.com/nicolargo/glances/wiki/The-Glances-API-How-To +Others outputs +============== + +Thanks to the -o option, it is possible to export statistics to CSV or HTML files. + +.. code-block:: console + + $ glances -o CSV -f /tmp/glances.csv + +CSV files have on line per stats: + +- load,load1,load5,load15 +- mem,total,used,free +- swap,total,used,free +- cpu,user,system,nice,idel,iowait,irq + +.. code-block:: console + + $ glances -o HTML -f /tmp + +Note: The css and img folders (glances/data) should be in the /tmp folder + Support ======= diff --git a/glances/glances.py b/glances/glances.py index 48ad8be9..442853c4 100644 --- a/glances/glances.py +++ b/glances/glances.py @@ -4005,8 +4005,12 @@ class glancesCsv: if stats.getCpu(): # Update CSV with the CPU stats cpu = stats.getCpu() - self.__csvfile.writerow(["cpu", cpu['user'], cpu['system'], - cpu['nice']]) + # Standard CPU stats + l = ["cpu", cpu['user'], cpu['system'], cpu['nice']] + # Extra CPU stats + for s in ('idle', 'iowait', 'irq'): + l.append(cpu[s] if cpu.has_key(s) else None) + self.__csvfile.writerow(l) if stats.getLoad(): # Update CSV with the LOAD stats load = stats.getLoad()