diff --git a/AUTHORS b/AUTHORS index b8784100..b08248bc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -20,8 +20,8 @@ https://github.com/jrenner Packagers ========= -Geoffroy Youri Berret for the Debian package -http://packages.debian.org/fr/sid/glances +Rémi Verchère for the Debian package +https://github.com/rverchere/debian-glances gasol.wu@gmail.com for the FreeBSD port diff --git a/glances/__init__.py b/glances/__init__.py index 5c195c82..bb7e08b1 100644 --- a/glances/__init__.py +++ b/glances/__init__.py @@ -37,19 +37,23 @@ except ImportError: print('psutil library not found. Glances cannot start.') sys.exit(1) -# Check psutil version -psutil_min_version = (2, 0, 0) -psutil_version = tuple([int(num) for num in __psutil_version.split('.')]) -if psutil_version < psutil_min_version: - print('psutil version {0} detected.').format(__psutil_version) - print('psutil 2.0 or higher is needed. Glances cannot start.') - sys.exit(1) - # Import Glances libs # Note: others Glances libs will be imported optionally from glances.core.glances_globals import gettext_domain, locale_dir, logger from glances.core.glances_main import GlancesMain +# Get PSutil version +psutil_min_version = (2, 0, 0) +psutil_version = tuple([int(num) for num in __psutil_version.split('.')]) + +# First log with Glances and PSUtil version +logger.info('Start Glances {} with PSutil {}'.format(__version__, __psutil_version)) + +# Check PSutil version +if psutil_version < psutil_min_version: + logger.critical('PSutil 2.0 or higher is needed. Glances cannot start.') + sys.exit(1) + def __signal_handler(signal, frame): """Callback for CTRL-C.""" diff --git a/glances/core/glances_config.py b/glances/core/glances_config.py index 1ea0d82e..2f5b1ae3 100644 --- a/glances/core/glances_config.py +++ b/glances/core/glances_config.py @@ -38,7 +38,8 @@ from glances.core.glances_globals import ( is_py3, is_windows, sys_prefix, - work_path + work_path, + logger ) @@ -69,9 +70,9 @@ class Config(object): self.parser.read(config_file, encoding='utf-8') else: self.parser.read(config_file) - # print(_("DEBUG: Read configuration file %s") % config_file) + logger.info(_("Read configuration file %s") % config_file) except UnicodeDecodeError as e: - print(_("Error: Cannot decode configuration file '{0}': {1}").format(config_file, e)) + logger.error(_("Cannot decode configuration file '{0}': {1}").format(config_file, e)) sys.exit(1) # Save the loaded configuration file path (issue #374) self._loaded_config_file = config_file diff --git a/glances/core/glances_monitor_list.py b/glances/core/glances_monitor_list.py index 08fc4286..59b51937 100644 --- a/glances/core/glances_monitor_list.py +++ b/glances/core/glances_monitor_list.py @@ -24,7 +24,7 @@ import re import subprocess # Import Glances lib -from glances.core.glances_globals import glances_processes +from glances.core.glances_globals import glances_processes, logger class MonitorList(object): @@ -72,7 +72,7 @@ class MonitorList(object): countmin = self.config.get_raw_option(section, key + "countmin") countmax = self.config.get_raw_option(section, key + "countmax") except Exception as e: - print(_("Error: Cannot read monitored list: {0}").format(e)) + logger.error(_("Cannot read monitored list: {0}").format(e)) pass else: if description is not None and regex is not None: diff --git a/glances/core/glances_password.py b/glances/core/glances_password.py index b1a906be..c7cc6be2 100644 --- a/glances/core/glances_password.py +++ b/glances/core/glances_password.py @@ -32,7 +32,8 @@ from glances.core.glances_globals import ( is_bsd, is_linux, is_mac, - is_windows + is_windows, + logger ) # Trick: bind raw_input to input in Python 2 @@ -106,7 +107,7 @@ class GlancesPassword(object): """ if os.path.exists(self.password_filepath) and not clear: # If the password file exist then use it - print(_("Info: Read password from file: {0}").format(self.password_filepath)) + logger.info(_("Read password from file: {0}").format(self.password_filepath)) password = self.load_password() else: # Else enter the password from the command line @@ -122,7 +123,7 @@ class GlancesPassword(object): password_confirm = hashlib.sha256(getpass.getpass(_("Password (confirm): ")).encode('utf-8')).hexdigest() if not self.check_password(password_hashed, password_confirm): - print(_("Error: Sorry, but passwords did not match...")) + logger.critical(_("Sorry, but passwords did not match...")) sys.exit(1) # Return the plain or hashed password @@ -147,7 +148,7 @@ class GlancesPassword(object): try: os.makedirs(self.password_path) except OSError as e: - print(_("Warning: Cannot create Glances directory: {0}").format(e)) + logger.error(_("Cannot create Glances directory: {0}").format(e)) return # Create/overwrite the password file diff --git a/glances/core/glances_snmp.py b/glances/core/glances_snmp.py index 934ceb52..7ab7a764 100644 --- a/glances/core/glances_snmp.py +++ b/glances/core/glances_snmp.py @@ -27,7 +27,7 @@ try: from pysnmp.entity.rfc3413.oneliner import cmdgen except ImportError: logger.critical(_("PySNMP library not found.")) - print(_("Install using pip: # pip install pysnmp")) + print(_("Install it using pip: # pip install pysnmp")) sys.exit(2) diff --git a/glances/core/glances_stats.py b/glances/core/glances_stats.py index 2b479411..78748493 100644 --- a/glances/core/glances_stats.py +++ b/glances/core/glances_stats.py @@ -95,7 +95,7 @@ class GlancesStats(object): # Restoring system path sys.path = sys_path # Log plugins list - logger.debug("Available plugins list: %s", self.getAllPlugins()) + logger.debug(_("Available plugins list: %s"), self.getAllPlugins()) def getAllPlugins(self): """Return the plugins list.""" @@ -105,7 +105,7 @@ class GlancesStats(object): """Load the stats limits.""" # For each plugins, call the init_limits method for p in self._plugins: - # print "DEBUG: Load limits for %s" % p + # logger.debug(_("Load limits for %s") % p) self._plugins[p].load_limits(config) def __update__(self, input_stats): @@ -113,8 +113,8 @@ class GlancesStats(object): if input_stats == {}: # For standalone and server modes # For each plugins, call the update method - for p in self._plugins: - # print "DEBUG: Update %s stats" % p + for p in self._plugins: + # logger.debug(_("Update %s stats") % p) self._plugins[p].update() else: # For Glances client mode @@ -193,8 +193,8 @@ class GlancesStatsClient(GlancesStats): # Add the plugin to the dictionary # The key is the plugin name # for example, the file glances_xxx.py - # generate self._plugins_list["xxx"] = ... - # print "DEBUG: Init %s plugin" % item + # generate self._plugins_list["xxx"] = ... + logger.debug(_("Init %s plugin") % item) self._plugins[item] = plugin.Plugin() # Restoring system path sys.path = sys_path @@ -267,9 +267,7 @@ class GlancesStatsClientSNMP(GlancesStats): for p in self._plugins: # Set the input method to SNMP self._plugins[p].set_input('snmp', self.system_name) - # print "DEBUG: Update %s stats using SNMP request" % p try: self._plugins[p].update() except Exception as e: - print(_("Error: Update {0} failed: {1}").format(p, e)) - # pass + logger.error(_("Error: Update {0} failed: {1}").format(p, e)) diff --git a/glances/outputs/glances_colorconsole.py b/glances/outputs/glances_colorconsole.py index f61f66a2..7a9c8018 100644 --- a/glances/outputs/glances_colorconsole.py +++ b/glances/outputs/glances_colorconsole.py @@ -21,12 +21,14 @@ import sys import threading import time +from glances.core.glances_globals import logger + import msvcrt try: import colorconsole import colorconsole.terminal except ImportError: - print('Colorconsole module not found. Glances cannot start in standalone mode.') + logger.critical(_('Colorconsole module not found. Glances cannot start in standalone mode.')) sys.exit(1) try: diff --git a/glances/outputs/glances_csv.py b/glances/outputs/glances_csv.py index ff378fb4..02ea9aa4 100644 --- a/glances/outputs/glances_csv.py +++ b/glances/outputs/glances_csv.py @@ -20,10 +20,11 @@ """CSV interface class.""" # Import sys libs -import csv import sys +import csv -# Import Glances libs +# Import Glances lib +from glances.core.glances_globals import logger from glances.core.glances_globals import is_py3 # List of stats enabled in the CSV output @@ -46,10 +47,10 @@ class GlancesCSV(object): self.csv_file = open(self.csv_filename, 'wb') self.writer = csv.writer(self.csv_file) except IOError as e: - print(_("Error: Cannot create the CSV file: {0}").format(e)) + logger.critical(_("Error: Cannot create the CSV file: {0}").format(e)) sys.exit(2) - print(_("Stats dumped to CSV file: {0}").format(self.csv_filename)) + logger.info(_("Stats dumped to CSV file: {0}").format(self.csv_filename)) def exit(self): """Close the CSV file.""" diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index 9223a3f9..e78ccd9c 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -32,7 +32,7 @@ if not is_windows: import curses import curses.panel except ImportError: - print('Curses module not found. Glances cannot start in standalone mode.') + logger.critical('Curses module not found. Glances cannot start in standalone mode.') sys.exit(1) else: from glances.outputs.glances_colorconsole import WCurseLight @@ -58,7 +58,7 @@ class GlancesCurses(object): # Init the curses screen self.screen = curses.initscr() if not self.screen: - print(_("Error: Cannot init the curses library.\n")) + logger.critical(_("Error: Cannot init the curses library.\n")) sys.exit(1) # Set curses options @@ -399,8 +399,6 @@ class GlancesCurses(object): self.new_line() self.display_plugin(stats_now) - # print "%s|%s" % (self.column, self.next_column) - # If space available... if screen_x > 52: # Restore line position diff --git a/glances/plugins/glances_batpercent.py b/glances/plugins/glances_batpercent.py index d083e78d..7be68c75 100644 --- a/glances/plugins/glances_batpercent.py +++ b/glances/plugins/glances_batpercent.py @@ -26,6 +26,7 @@ except ImportError: pass # Import Glances libs +from glances.core.glances_globals import logger from glances.plugins.glances_plugin import GlancesPlugin @@ -84,7 +85,7 @@ class GlancesGrabBat(object): self.bat_list = [] self.update() except Exception: - # print(_("Warning: Cannot grab battery sensor. Missing BatInfo library.")) + logger.error(_("Cannot grab battery sensor. Missing BatInfo library.")) self.initok = False def update(self): diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 93bcb9e4..2d8c6050 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -91,7 +91,6 @@ class Plugin(GlancesPlugin): # Windows or VMWare ESXi # You can find the CPU utilization of windows system by querying the oid # Give also the number of core (number of element in the table) - # print snmp_oid[self.get_short_system_name()] try: cpu_stats = self.set_stats_snmp(snmp_oid=snmp_oid[self.get_short_system_name()], bulk=True) diff --git a/glances/plugins/glances_monitor.py b/glances/plugins/glances_monitor.py index 8ee537b2..d4737ee4 100644 --- a/glances/plugins/glances_monitor.py +++ b/glances/plugins/glances_monitor.py @@ -20,6 +20,7 @@ """Monitor plugin.""" # Import Glances lib +from glances.core.glances_globals import logger from glances.core.glances_monitor_list import MonitorList as glancesMonitorList from glances.plugins.glances_plugin import GlancesPlugin @@ -41,7 +42,7 @@ class Plugin(GlancesPlugin): def load_limits(self, config): """Load the monitored list from the conf file.""" - # print "DEBUG: Monitor plugin load config file %s" % config + logger.debug(_("Monitor plugin configuration detected in the configuration file")) self.glances_monitors = glancesMonitorList(config) def update(self): diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index e891612c..a9b75efe 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -131,13 +131,6 @@ class GlancesPlugin(object): if item_stats != {}: ret[item_key] = item_stats index += 1 - - # if '1.3.6.1.2.1.25.3.3.1.2' in snmp_oid.values(): - # # if '1.3.6.1.2.1.25.2.3.1.3' in snmp_oid.values(): - # print snmp_oid - # print snmpresult - # print ret - else: # Simple get request snmpresult = clientsnmp.get_by_oid(*snmp_oid.values()) @@ -160,10 +153,8 @@ class GlancesPlugin(object): """Load the limits from the configuration file.""" if (hasattr(config, 'has_section') and config.has_section(self.plugin_name)): - # print "Load limits for %s" % self.plugin_name for s, v in config.items(self.plugin_name): # Read limits - # print "\t%s = %s" % (self.plugin_name + '_' + s, v) try: self.limits[self.plugin_name + '_' + s] = config.get_option(self.plugin_name, s) except ValueError: