Add CPU stats to the CSV output

This commit is contained in:
Nicolas Hennion 2013-12-30 16:45:45 +01:00
parent 4dd4461989
commit 9af0cb5431
2 changed files with 29 additions and 2 deletions

View File

@ -518,6 +518,7 @@ else:
On the left, you can easily see if you are connected to a Glances server. On the left, you can easily see if you are connected to a Glances server.
API documentation 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 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 Support
======= =======

View File

@ -4005,8 +4005,12 @@ class glancesCsv:
if stats.getCpu(): if stats.getCpu():
# Update CSV with the CPU stats # Update CSV with the CPU stats
cpu = stats.getCpu() cpu = stats.getCpu()
self.__csvfile.writerow(["cpu", cpu['user'], cpu['system'], # Standard CPU stats
cpu['nice']]) 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(): if stats.getLoad():
# Update CSV with the LOAD stats # Update CSV with the LOAD stats
load = stats.getLoad() load = stats.getLoad()