From 257a5a3d7b3f61b8d3a84697cde2f7bf8d85bc34 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Wed, 22 Feb 2017 12:50:40 +0100 Subject: [PATCH 1/6] Fix regression introduced which broke config (#1038) On Windows, fallback to %APPDATA% if %LOCALAPPDATA% doesn't exist. --- glances/config.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/glances/config.py b/glances/config.py index 21813a55..4698e9e9 100644 --- a/glances/config.py +++ b/glances/config.py @@ -42,6 +42,7 @@ def user_config_dir(): path = os.path.expanduser('~/Library/Application Support') else: path = os.environ.get('XDG_CONFIG_HOME') or os.path.expanduser('~/.config') + path = os.path.join(path, 'glances') return path @@ -51,10 +52,11 @@ def user_cache_dir(): - Linux, *BSD, SunOS: ~/.cache/glances - macOS: ~/Library/Caches/glances - - Windows: %LOCALAPPDATA%\glances\cache + - Windows: {%LOCALAPPDATA%,%APPDATA%}\glances\cache """ - if WINDOWS and os.environ.get('LOCALAPPDATA') is not None: - path = os.path.join(os.environ.get('LOCALAPPDATA'), 'glances', 'cache') + if WINDOWS: + path = os.path.join(os.environ.get('LOCALAPPDATA') or os.environ.get('APPDATA'), + 'glances', 'cache') elif MACOS: path = os.path.expanduser('~/Library/Caches/glances') else: @@ -77,6 +79,7 @@ def system_config_dir(): path = '/usr/local/etc' else: path = os.environ.get('APPDATA') + path = os.path.join(path, 'glances') return path @@ -118,10 +121,8 @@ class Config(object): if self.config_dir: paths.append(self.config_dir) - if user_config_dir() is not None: - paths.append(os.path.join(user_config_dir(), self.config_filename)) - if system_config_dir() is not None: - paths.append(os.path.join(system_config_dir(), self.config_filename)) + paths.append(os.path.join(user_config_dir(), self.config_filename)) + paths.append(os.path.join(system_config_dir(), self.config_filename)) return paths From f5bbd9ed4d31145aa532e3576f765531b7a7d5e0 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Wed, 22 Feb 2017 16:12:46 +0100 Subject: [PATCH 2/6] Do not use backslash for line continuation The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses. Fix wrong indentation too. --- glances/client.py | 4 +-- glances/main.py | 51 +++++++++++++------------------ glances/outdated.py | 4 +-- glances/outputs/glances_curses.py | 18 ++++++----- glances/plugins/glances_cloud.py | 4 +-- glances/plugins/glances_docker.py | 4 +-- glances/plugins/glances_fs.py | 3 +- glances/plugins/glances_ports.py | 6 ++-- 8 files changed, 42 insertions(+), 52 deletions(-) diff --git a/glances/client.py b/glances/client.py index ae980b6a..02f3c572 100644 --- a/glances/client.py +++ b/glances/client.py @@ -124,8 +124,8 @@ class GlancesClient(object): self.stats.set_plugins(json.loads(self.client.getAllPlugins())) logger.debug("Client version: {} / Server version: {}".format(__version__, client_version)) else: - self.log_and_exit("Client and server not compatible: \ - Client version: {} / Server version: {}".format(__version__, client_version)) + self.log_and_exit(('Client and server not compatible: ' + 'Client version: {} / Server version: {}'.format(__version__, client_version))) return False return True diff --git a/glances/main.py b/glances/main.py index 1fbd19e4..853b112d 100644 --- a/glances/main.py +++ b/glances/main.py @@ -363,30 +363,28 @@ Start the client browser (browser mode):\n\ self.args = args # Export is only available in standalone or client mode (issue #614) - export_tag = args.export_csv or \ - args.export_elasticsearch or \ - args.export_statsd or \ - args.export_influxdb or \ - args.export_cassandra or \ - args.export_opentsdb or \ - args.export_rabbitmq or \ + export_tag = ( + args.export_csv or + args.export_elasticsearch or + args.export_statsd or + args.export_influxdb or + args.export_cassandra or + args.export_opentsdb or + args.export_rabbitmq or args.export_couchdb + ) if WINDOWS and export_tag: # On Windows, export is possible but only in quiet mode # See issue #1038 - logger.info( - "On Windows OS, export disable the Web Interface") + logger.info("On Windows OS, export disable the Web interface") self.args.quiet = True self.args.webserver = False - elif not (self.is_standalone() or self.is_client()) \ - and export_tag: - logger.critical( - "Export is only available in standalone or client mode") + elif not (self.is_standalone() or self.is_client()) and export_tag: + logger.critical("Export is only available in standalone or client mode") sys.exit(2) # Filter is only available in standalone mode - if args.process_filter is not None \ - and not self.is_standalone(): + if args.process_filter is not None and not self.is_standalone(): logger.critical( "Process filter is only available in standalone mode") sys.exit(2) @@ -394,8 +392,7 @@ Start the client browser (browser mode):\n\ # Check graph output path if args.export_graph and args.path_graph is not None: if not os.access(args.path_graph, os.W_OK): - logger.critical( - "Graphs output path {} doesn't exist or is not writable".format(args.path_graph)) + logger.critical("Graphs output path {} doesn't exist or is not writable".format(args.path_graph)) sys.exit(2) logger.debug( "Graphs output path is set to {}".format(args.path_graph)) @@ -429,30 +426,26 @@ Start the client browser (browser mode):\n\ def is_standalone(self): """Return True if Glances is running in standalone mode.""" - return not self.args.client \ - and not self.args.browser \ - and not self.args.server \ - and not self.args.webserver + return (not self.args.client and + not self.args.browser and + not self.args.server and + not self.args.webserver) def is_client(self): """Return True if Glances is running in client mode.""" - return (self.args.client or self.args.browser) \ - and not self.args.server + return (self.args.client or self.args.browser) and not self.args.server def is_client_browser(self): """Return True if Glances is running in client browser mode.""" - return self.args.browser \ - and not self.args.server + return self.args.browser and not self.args.server def is_server(self): """Return True if Glances is running in server mode.""" - return not self.args.client \ - and self.args.server + return not self.args.client and self.args.server def is_webserver(self): """Return True if Glances is running in Web server mode.""" - return not self.args.client \ - and self.args.webserver + return not self.args.client and self.args.webserver def get_config(self): """Return configuration file object.""" diff --git a/glances/outdated.py b/glances/outdated.py index 5bfd683b..4c4452a2 100644 --- a/glances/outdated.py +++ b/glances/outdated.py @@ -135,8 +135,8 @@ class Outdated(object): logger.debug("Cannot read the version cache file: {}".format(e)) else: logger.debug("Read the version cache file") - if cached_data['installed_version'] != self.installed_version() or \ - datetime.now() - cached_data['refresh_date'] > self.max_refresh_date: + if (cached_data['installed_version'] != self.installed_version() or + datetime.now() - cached_data['refresh_date'] > self.max_refresh_date): # Reset the cache if: # - the installed version is different # - the refresh_date is > max_refresh_date diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index edf89631..3234775a 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -515,9 +515,11 @@ class _GlancesCurses(object): __stat_display = self.__get_stat_display(stats, plugin_max_width) # Adapt number of processes to the available space - max_processes_displayed = self.screen.getmaxyx()[0] - 11 - \ - self.get_stats_display_height(__stat_display["alert"]) - \ + max_processes_displayed = ( + self.screen.getmaxyx()[0] - 11 - + self.get_stats_display_height(__stat_display["alert"]) - self.get_stats_display_height(__stat_display["docker"]) + ) try: if self.args.enable_process_extended and not self.args.process_tree: max_processes_displayed -= 4 @@ -618,10 +620,10 @@ class _GlancesCurses(object): # Space between column self.space_between_column = 0 self.new_line() - l_uptime = self.get_stats_display_width(stat_display["system"]) \ - + self.space_between_column \ - + self.get_stats_display_width(stat_display["ip"]) + 3 \ - + self.get_stats_display_width(stat_display["uptime"]) + l_uptime = (self.get_stats_display_width(stat_display["system"]) + + self.space_between_column + + self.get_stats_display_width(stat_display["ip"]) + 3 + + self.get_stats_display_width(stat_display["uptime"])) self.display_plugin( stat_display["system"], display_optional=(self.screen.getmaxyx()[1] >= l_uptime)) @@ -722,8 +724,8 @@ class _GlancesCurses(object): if not self.args.disable_left_sidebar: for s in ['network', 'wifi', 'ports', 'diskio', 'fs', 'irq', 'folders', 'raid', 'sensors', 'now']: - if (hasattr(self.args, 'enable_' + s) or - hasattr(self.args, 'disable_' + s)) and s in stat_display: + if ((hasattr(self.args, 'enable_' + s) or + hasattr(self.args, 'disable_' + s)) and s in stat_display): self.new_line() self.display_plugin(stat_display[s]) diff --git a/glances/plugins/glances_cloud.py b/glances/plugins/glances_cloud.py index b60a3832..30e12369 100644 --- a/glances/plugins/glances_cloud.py +++ b/glances/plugins/glances_cloud.py @@ -100,9 +100,7 @@ class Plugin(GlancesPlugin): # Init the return message ret = [] - if not self.stats \ - or self.stats == {} \ - or self.is_disable(): + if not self.stats or self.stats == {} or self.is_disable(): return ret # Generate the output diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py index a90c073d..a5bdcc55 100644 --- a/glances/plugins/glances_docker.py +++ b/glances/plugins/glances_docker.py @@ -524,9 +524,7 @@ class Plugin(GlancesPlugin): ret = [] # Only process if stats exist (and non null) and display plugin enable... - if not self.stats \ - or len(self.stats['containers']) == 0 \ - or self.is_disable(): + if not self.stats or len(self.stats['containers']) == 0 or self.is_disable(): return ret # Build the string message diff --git a/glances/plugins/glances_fs.py b/glances/plugins/glances_fs.py index 3162666b..adf415c6 100644 --- a/glances/plugins/glances_fs.py +++ b/glances/plugins/glances_fs.py @@ -229,8 +229,7 @@ class Plugin(GlancesPlugin): mnt_point = i['mnt_point'][-fsname_max_width + 1:] elif len(i['mnt_point']) + len(i['device_name'].split('/')[-1]) <= fsname_max_width - 3: # If possible concatenate mode info... Glances touch inside :) - mnt_point = i['mnt_point'] + \ - ' (' + i['device_name'].split('/')[-1] + ')' + mnt_point = i['mnt_point'] + ' (' + i['device_name'].split('/')[-1] + ')' elif len(i['mnt_point']) > fsname_max_width: # Cut mount point name if it is too long mnt_point = '_' + i['mnt_point'][-fsname_max_width + 1:] diff --git a/glances/plugins/glances_ports.py b/glances/plugins/glances_ports.py index 3b25f160..93f939e0 100644 --- a/glances/plugins/glances_ports.py +++ b/glances/plugins/glances_ports.py @@ -100,9 +100,9 @@ class Plugin(GlancesPlugin): return 'CAREFUL' elif port['status'] == 0: return 'CRITICAL' - elif isinstance(port['status'], (float, int)) and \ - port['rtt_warning'] is not None and \ - port['status'] > port['rtt_warning']: + elif (isinstance(port['status'], (float, int)) and + port['rtt_warning'] is not None and + port['status'] > port['rtt_warning']): return 'WARNING' return 'OK' From fef6f8a8608027460ed3014dbfd35a715cfe3cbb Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Wed, 22 Feb 2017 19:28:22 +0100 Subject: [PATCH 3/6] Use triple quotation marks for epilog --- glances/main.py | 57 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/glances/main.py b/glances/main.py index 853b112d..0c1c3dda 100644 --- a/glances/main.py +++ b/glances/main.py @@ -49,35 +49,34 @@ class GlancesMain(object): username = "glances" password = "" - # Exemple of use - example_of_use = "\ -Examples of use:\n\ -\n\ -Monitor local machine (standalone mode):\n\ - $ glances\n\ -\n\ -Monitor local machine with the Web interface (Web UI):\n\ - $ glances -w\n\ - Glances web server started on http://0.0.0.0:61208/\n\ -\n\ -Monitor local machine and export stats to a CSV file (standalone mode):\n\ - $ glances --export-csv /tmp/glances.csv\n\ -\n\ -Monitor local machine and export stats to a InfluxDB server with 5s refresh time (standalone mode):\n\ - $ glances -t 5 --export-influxdb\n\ -\n\ -Start a Glances server (server mode):\n\ - $ glances -s\n\ -\n\ -Connect Glances to a Glances server (client mode):\n\ - $ glances -c \n\ -\n\ -Connect Glances to a Glances server and export stats to a StatsD server (client mode):\n\ - $ glances -c --export-statsd\n\ -\n\ -Start the client browser (browser mode):\n\ - $ glances --browser\n\ - " + # Examples of use + example_of_use = """ +Examples of use: + Monitor local machine (standalone mode): + $ glances + + Monitor local machine with the Web interface (Web UI): + $ glances -w + Glances web server started on http://0.0.0.0:61208/ + + Monitor local machine and export stats to a CSV file (standalone mode): + $ glances --export-csv /tmp/glances.csv + + Monitor local machine and export stats to a InfluxDB server with 5s refresh time (standalone mode): + $ glances -t 5 --export-influxdb + + Start a Glances server (server mode): + $ glances -s + + Connect Glances to a Glances server (client mode): + $ glances -c + + Connect Glances to a Glances server and export stats to a StatsD server (client mode): + $ glances -c --export-statsd + + Start the client browser (browser mode): + $ glances --browser +""" def __init__(self): """Manage the command line arguments.""" From 7ad5b2e6e851da951dda7b185a86298ca60753e8 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Thu, 23 Feb 2017 11:11:44 +0100 Subject: [PATCH 4/6] Improve documentation about TEMP on Windows --- docs/config.rst | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index c2be2ac6..beee972c 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -23,17 +23,8 @@ You can put your own ``glances.conf`` file in the following locations: ``Windows`` %APPDATA%\\glances ==================== ============================================================= -On Windows XP, the ``%APPDATA%`` path is: - -:: - - C:\Documents and Settings\\Application Data - -Since Windows Vista and newer versions: - -:: - - C:\Users\\AppData\Roaming +* On Windows XP, ``%APPDATA%`` is: ``C:\Documents and Settings\\Application Data``. +* On Windows Vista and later: ``C:\Users\\AppData\Roaming``. User-specific options override system-wide options and options given on the command line override either. @@ -107,10 +98,13 @@ line. By default, the ``glances-USERNAME.log`` file is under the temporary directory: -=========== ====================== +=========== ====== ``*nix`` /tmp -``Windows`` %APPDATA%\\Local\\temp -=========== ====================== +``Windows`` %TEMP% +=========== ====== + +* On Windows XP, ``%TEMP%`` is: ``C:\Documents and Settings\\Local Settings\Temp``. +* On Windows Vista and later: ``C:\Users\\AppData\Local\Temp``. If you want to use another system path or change the log message, you can use your own logger configuration. First of all, you have to create From 932f8ee841e70431cd5a3ff7321fefdb67bfc50b Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Thu, 23 Feb 2017 11:23:43 +0100 Subject: [PATCH 5/6] Add CONFIGURATION section to man page --- docs/glances.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/glances.rst b/docs/glances.rst index a353fd5d..5f00a0b4 100644 --- a/docs/glances.rst +++ b/docs/glances.rst @@ -26,6 +26,11 @@ OPTIONS .. include:: cmds.rst +CONFIGURATION +------------- + +.. include:: config.rst + EXAMPLES -------- From 2b3ebb5885d103a55763ac3116e266a07b465ef0 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Thu, 23 Feb 2017 12:48:58 +0100 Subject: [PATCH 6/6] Fix formatting for CPU stats documentation --- docs/aoa/cpu.rst | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/docs/aoa/cpu.rst b/docs/aoa/cpu.rst index c8acde26..ead6a0df 100644 --- a/docs/aoa/cpu.rst +++ b/docs/aoa/cpu.rst @@ -15,25 +15,33 @@ displayed. CPU stats description: -* user: percent time spent in user space -> User CPU time is time spent on the processor running your program's code (or code in libraries) -* system: percent time spent in kernel space -> System CPU time is the time spent running code in the operating system kernel -* idle: percent of CPU used by any program -> Every program or task that runs on a computer system occupies a certain amount of processing time on the CPU. If the CPU has completed all tasks it is idle. -* nice: percent time occupied by user level processes with a positive nice value -> The time the CPU has spent running users' processes that have been "niced" -* irq: percent time spent servicing/handling hardware/software interrupts -> Time servicing interrupts (hardware + software) -* iowait: percent time spent in wait (on disk) -> Time spent by the CPU waiting for a IO operations to complete -* steal: percent time in involuntary wait by virtual CPU -> Steal time is the percentage of time a virtual CPU waits for a real CPU while the hypervisor is servicing another virtual processor -* ctx_sw: number of context switches (voluntary + involuntary) per second -> A context switch is a procedure that a computer's CPU (central processing unit) follows to change from one task (or process) to another while ensuring that the tasks do not conflict -* inter: number of interrupts per second -* sw_inter: number of software interrupts per second. Always set to 0 on Windows and SunOS. -* syscal: number of system calls per second. Do not displayed on Linux (always 0). +- **user**: percent time spent in user space. User CPU time is the time + spent on the processor running your program's code (or code in + libraries). +- **system**: percent time spent in kernel space. System CPU time is the + time spent running code in the Operating System kernel. +- **idle**: percent of CPU used by any program. Every program or task + that runs on a computer system occupies a certain amount of processing + time on the CPU. If the CPU has completed all tasks it is idle. +- **nice** *(\*nix)*: percent time occupied by user level processes with + a positive nice value. The time the CPU has spent running users' + processes that have been *niced*. +- **irq** *(Linux, \*BSD)*: percent time spent servicing/handling + hardware/software interrupts. Time servicing interrupts (hardware + + software). +- **iowait** *(Linux)*: percent time spent by the CPU waiting for I/O + operations to complete. +- **steal** *(Linux)*: percentage of time a virtual CPU waits for a real + CPU while the hypervisor is servicing another virtual processor. +- **ctx_sw**: number of context switches (voluntary + involuntary) per + second. A context switch is a procedure that a computer's CPU (central + processing unit) follows to change from one task (or process) to + another while ensuring that the tasks do not conflict. +- **inter**: number of interrupts per second. +- **sw_inter**: number of software interrupts per second. Always set to + 0 on Windows and SunOS. +- **syscal**: number of system calls per second. Do not displayed on + Linux (always 0). To switch to per-CPU stats, just hit the ``1`` key: