diff --git a/docs/glances-doc.html b/docs/glances-doc.html index f1476601..68e3a0e8 100644 --- a/docs/glances-doc.html +++ b/docs/glances-doc.html @@ -125,7 +125,7 @@ td.option-group {

This manual describes Glances version 1.7.6.

Copyright © 2012-2014 Nicolas Hennion <nicolas@nicolargo.com>

-

March 2014

+

May 2014

Table of Contents

  • API documentation
  • -
  • Others outputs
  • +
  • Other outputs
  • Support
  • @@ -231,8 +231,8 @@ just run on the server:

    -e Enable sensors module (requires pysensors, Linux-only) --f FILE -Set the HTML output folder or CSV file +-f FOLDER +Set the HTML or CSV output folder -h Display the help and exit @@ -636,23 +636,25 @@ is installed on your system then Glances displays the available percent capacity

    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.

    +
    +

    Other outputs

    +

    Thanks to the -o (output) option, it is possible to export statistics to CSV or HTML files.

    -$ glances -o CSV -f /tmp/glances.csv
    +$ glances -o CSV -f /tmp
     
    +

    The CSV output file is named glances.csv.

    CSV files have on line per stats:

     $ glances -o HTML -f /tmp
     
    -

    Note: The css and img folders (glances/data) should be in the /tmp folder

    +

    The HTML output file is named glances.html.

    +

    Note: The css and img folders (glances/data) should be in the /tmp folder.

    Support

    diff --git a/docs/glances-doc.rst b/docs/glances-doc.rst index 3ea77b44..21db8ef2 100644 --- a/docs/glances-doc.rst +++ b/docs/glances-doc.rst @@ -6,7 +6,7 @@ This manual describes *Glances* version 1.7.6. Copyright © 2012-2014 Nicolas Hennion -March 2014 +May 2014 .. contents:: Table of Contents @@ -84,7 +84,7 @@ Command-line options -C FILE Path to the configuration file -d Disable disk I/O module -e Enable sensors module (requires pysensors, Linux-only) --f FILE Set the HTML output folder or CSV file +-f FOLDER Set the HTML or CSV output folder -h Display the help and exit -m Disable mount module -n Disable network module @@ -374,7 +374,7 @@ Three views are available for processes: The processes summary line display: * Tasks number (total number of processes) -* Threads number +* Threads number * Running tasks number * Sleeping tasks number * Other tasks number (not running or sleeping) @@ -528,27 +528,31 @@ 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 -============== +Other outputs +============= -Thanks to the -o option, it is possible to export statistics to CSV or HTML files. +Thanks to the -o (output) option, it is possible to export statistics to `CSV` or `HTML` files. .. code-block:: console - $ glances -o CSV -f /tmp/glances.csv + $ glances -o CSV -f /tmp + +The CSV output file is named ``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 +- cpu,user,system,nice,idle,iowait,irq .. code-block:: console $ glances -o HTML -f /tmp -Note: The css and img folders (glances/data) should be in the /tmp folder +The HTML output file is named ``glances.html``. + +*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 d173c6a7..6ac6b88b 100644 --- a/glances/glances.py +++ b/glances/glances.py @@ -48,6 +48,9 @@ import collections from base64 import b64decode from hashlib import md5 +# PY3? +is_PY3 = sys.version_info >= (3, 2) + # Somes libs depends of OS is_BSD = sys.platform.find('bsd') != -1 is_Linux = sys.platform.startswith('linux') @@ -167,7 +170,7 @@ try: # CSV output (optional) import csv except ImportError: - cvs_lib_tag = False + csv_lib_tag = False else: csv_lib_tag = True @@ -397,7 +400,7 @@ class Config: for path in self.get_paths_list(): if os.path.isfile(path) and os.path.getsize(path) > 0: try: - if sys.version_info >= (3, 2): + if is_PY3: self.parser.read(path, encoding='utf-8') else: self.parser.read(path) @@ -4043,10 +4046,10 @@ class glancesHtml: self.__refresh_time = refresh_time # Set the HTML output file - self.html_file = os.path.join(html_path, html_filename) + self.html_file = os.path.realpath(os.path.join(html_path, html_filename)) # Get data path - data_path = os.path.join(work_path, 'data') + data_path = os.path.realpath(os.path.join(work_path, 'data')) # Set the template path template_path = os.path.join(data_path, 'html') @@ -4168,45 +4171,50 @@ class glancesCsv: This class manages the CSV output """ - def __init__(self, cvsfile="./glances.csv", refresh_time=1): - # Init refresh time + def __init__(self, csv_path, refresh_time=1): + csv_filename = 'glances.csv' self.__refresh_time = refresh_time - # Set the ouput (CSV) path + # Set the CSV output file + csv_file = os.path.realpath(os.path.join(csv_path, csv_filename)) + try: - self.__cvsfile_fd = open("%s" % cvsfile, "wb") - self.__csvfile = csv.writer(self.__cvsfile_fd) + if is_PY3: + self.__csvfile_fd = open(csv_file, 'w', newline='') + else: + self.__csvfile_fd = open(csv_file, 'wb') + self.__csvfile = csv.writer(self.__csvfile_fd) except IOError as error: - print("Cannot create the output CSV file: ", error[1]) - sys.exit(0) + print(_("Cannot create the CSV output file: %s") % error) + sys.exit(2) def exit(self): - self.__cvsfile_fd.close() + self.__csvfile_fd.close() def update(self, stats): if stats.getCpu(): # Update CSV with the CPU stats cpu = stats.getCpu() # Standard CPU stats - l = ["cpu", cpu['user'], cpu['system'], cpu['nice']] + cpu_line = ["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) + for key in ('idle', 'iowait', 'irq'): + cpu_line.append(cpu[key] if key in cpu.keys() else None) + self.__csvfile.writerow(cpu_line) if stats.getLoad(): # Update CSV with the LOAD stats load = stats.getLoad() - self.__csvfile.writerow(["load", load['min1'], load['min5'], - load['min15']]) + self.__csvfile.writerow( + ["load", load['min1'], load['min5'], load['min15']]) if stats.getMem() and stats.getMemSwap(): # Update CSV with the MEM stats mem = stats.getMem() - self.__csvfile.writerow(["mem", mem['total'], mem['used'], - mem['free']]) + self.__csvfile.writerow( + ["mem", mem['total'], mem['used'], mem['free']]) memswap = stats.getMemSwap() - self.__csvfile.writerow(["swap", memswap['total'], memswap['used'], - memswap['free']]) - self.__cvsfile_fd.flush() + self.__csvfile.writerow( + ["swap", memswap['total'], memswap['used'], memswap['free']]) + self.__csvfile_fd.flush() class GlancesXMLRPCHandler(SimpleXMLRPCRequestHandler): @@ -4529,7 +4537,7 @@ def printSyntax(): print(_("\t-C FILE\t\tPath to the configuration file")) print(_("\t-d\t\tDisable disk I/O module")) print(_("\t-e\t\tEnable sensors module")) - print(_("\t-f FILE\t\tSet the HTML output folder or CSV file")) + print(_("\t-f FOLDER\tSet the HTML or CSV output folder")) print(_("\t-h\t\tDisplay the help and exit")) print(_("\t-m\t\tDisable mount module")) print(_("\t-n\t\tDisable network module")) @@ -4693,8 +4701,7 @@ def main(): sensors_tag = True elif opt in ("-y", "--hddtemp"): hddtemp_tag = True - elif opt in ("-f", "--file"): - output_file = arg + elif opt in ("-f", "--folder"): output_folder = arg elif opt in ("-t", "--time"): if not (arg.isdigit() and int(arg) > 0): @@ -4755,8 +4762,7 @@ def main(): try: output_folder except UnboundLocalError: - print(_("Error: HTML export (-o html) need " - "output folder definition (-f )")) + print(_("Error: HTML export (-o html) need output folder definition (-f )")) sys.exit(2) if csv_tag: @@ -4764,10 +4770,9 @@ def main(): print(_("Error: Need CSV library to export into CSV")) sys.exit(2) try: - output_file + output_folder except UnboundLocalError: - print(_("Error: CSV export (-o csv) need " - "output file definition (-f )")) + print(_("Error: CSV export (-o csv) need output folder definition (-f )")) sys.exit(2) # Catch CTRL-C @@ -4863,7 +4868,7 @@ def main(): # Init CSV output if csv_tag: - csvoutput = glancesCsv(cvsfile=output_file, + csvoutput = glancesCsv(csv_path=output_folder, refresh_time=refresh_time) # Init screen diff --git a/man/glances.1 b/man/glances.1 index 6f577e5b..9fa8d072 100644 --- a/man/glances.1 +++ b/man/glances.1 @@ -1,4 +1,4 @@ -.TH glances 1 "March, 2014" "version 1.7.6" "USER COMMANDS" +.TH glances 1 "May, 2014" "version 1.7.6" "USER COMMANDS" .SH NAME glances \- A cross-platform curses-based monitoring tool .SH SYNOPSIS @@ -34,8 +34,8 @@ Disable disk I/O module .B \-e Enable sensors module (requires pysensors, Linux-only) .TP -.B \-f FILE -Set the HTML output folder or CSV file +.B \-f FOLDER +Set the HTML or CSV output folder .TP .B \-h Display the help and exit