diff options
Diffstat (limited to 'glances')
96 files changed, 4046 insertions, 1835 deletions
diff --git a/glances/README.txt b/glances/README.txt index fe29ae0e..b512e62b 100644 --- a/glances/README.txt +++ b/glances/README.txt @@ -1,6 +1,7 @@ -You are in the main Glances's source folder. This page is **ONLY** for developpers purposes. +You are in the main Glances source folder. This page is **ONLY** for developers. -If you are looking for the user manual, please follow this link: https://github.com/nicolargo/glances/blob/master/docs/glances-doc.rst +If you are looking for the user manual, please follow this link: +https://github.com/nicolargo/glances/blob/master/docs/glances-doc.rst === @@ -9,11 +10,10 @@ __main__.py Entry point for Glances module core/ => Glances core folder glances_config.py Manage configuration file - glances_globals.py Share variables uppon modules + glances_globals.py Share variables upon modules glances_limits.py Manage limits glances_logs.py Manage logs glances_main.py Main script to rule them up... - glances_stats.py Inteface to grab stats glances_client.py Glances client glances_server.py Glances server glances_standalone.py Glances standalone (with curse interface) diff --git a/glances/__init__.py b/glances/__init__.py index 30636edb..68a8803f 100644 --- a/glances/__init__.py +++ b/glances/__init__.py @@ -20,12 +20,11 @@ """Init the Glances software.""" __appname__ = 'glances' -__version__ = '2.3' +__version__ = '2.4' __author__ = 'Nicolas Hennion <nicolas@nicolargo.com>' __license__ = 'LGPL' # Import system lib -import gettext import locale import platform import signal @@ -40,23 +39,24 @@ except ImportError: # Import Glances libs # Note: others Glances libs will be imported optionally -from glances.core.glances_globals import gettext_domain, locale_dir from glances.core.glances_logging import 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('.')]) +try: + locale.setlocale(locale.LC_ALL, '') +except locale.Error: + print("Warning: Unable to set locale. Expect encoding problems.") -# First log with Glances and PSUtil version -logger.info('Start Glances {0}'.format(__version__)) -logger.info('{0} {1} and PSutil {2} detected'.format(platform.python_implementation(), - platform.python_version(), - __psutil_version)) +# Check Python version +if sys.version_info < (2, 6) or (3, 0) <= sys.version_info < (3, 3): + print('Glances requires at least Python 2.6 or 3.3 to run.') + 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: - logger.critical('PSutil 2.0 or higher is needed. Glances cannot start.') + print('PSutil 2.0 or higher is needed. Glances cannot start.') sys.exit(1) @@ -94,9 +94,12 @@ def main(): Select the mode (standalone, client or server) Run it... """ - # Setup translations - locale.setlocale(locale.LC_ALL, '') - gettext.install(gettext_domain, locale_dir) + # Log Glances and PSutil version + logger.info('Start Glances {0}'.format(__version__)) + logger.info('{0} {1} and PSutil {2} detected'.format( + platform.python_implementation(), + platform.python_version(), + __psutil_version)) # Share global var global core, standalone, client, server, webserver @@ -164,7 +167,7 @@ def main(): server = GlancesServer(cached_time=core.cached_time, config=core.get_config(), args=args) - print(_("Glances server is running on {0}:{1}").format(args.bind_address, args.port)) + print('Glances server is running on {0}:{1}'.format(args.bind_address, args.port)) # Set the server login/password (if -P/--password tag) if args.password != "": diff --git a/glances/core/glances_actions.py b/glances/core/glances_actions.py index 1a762b70..dabcd1ba 100644 --- a/glances/core/glances_actions.py +++ b/glances/core/glances_actions.py @@ -19,11 +19,12 @@ """Manage on alert actions.""" +# Import system lib +from subprocess import Popen + # Import Glances lib from glances.core.glances_logging import logger -# Import system lib -from subprocess import Popen try: import pystache except ImportError: @@ -35,11 +36,10 @@ else: class GlancesActions(object): - """This class manage action if an alert is reached""" + """This class manage action if an alert is reached.""" def __init__(self): - """Init GlancesActions class""" - + """Init GlancesActions class.""" # Dict with the criticity status # - key: stat_name # - value: criticity @@ -47,25 +47,26 @@ class GlancesActions(object): self.status = {} def get(self, stat_name): - """Get the stat_name criticity""" + """Get the stat_name criticity.""" try: return self.status[stat_name] except KeyError: return None def set(self, stat_name, criticity): - """Set the stat_name to criticity""" + """Set the stat_name to criticity.""" self.status[stat_name] = criticity def run(self, stat_name, criticity, commands, mustache_dict=None): - """Run the commands (in background) + """Run the commands (in background). + - stats_name: plugin_name (+ header) - criticity: criticity of the trigger - commands: a list of command line with optional {{mustache}} - mustache_dict: Plugin stats (can be use within {{mustache}}) - Return True if the commands have been ran""" - + Return True if the commands have been ran. + """ if self.get(stat_name) == criticity: # Action already executed => Exit return False @@ -75,7 +76,7 @@ class GlancesActions(object): criticity, mustache_dict)) - # Ran all actions in background + # Run all actions in background for cmd in commands: # Replace {{arg}} by the dict one (Thk to {Mustache}) if pystache_tag: diff --git a/glances/core/glances_autodiscover.py b/glances/core/glances_autodiscover.py index f9659f08..3648e35f 100644 --- a/glances/core/glances_autodiscover.py +++ b/glances/core/glances_autodiscover.py @@ -22,11 +22,7 @@ # Import system libs import socket import sys -try: - import netifaces - netifaces_tag = True -except ImportError: - netifaces_tag = False + try: from zeroconf import ( __version__ as __zeroconf_version, @@ -42,13 +38,13 @@ except ImportError: from glances.core.glances_globals import appname from glances.core.glances_logging import logger -# Zeroconf 0.16 or higher is needed +# Zeroconf 0.17 or higher is needed if zeroconf_tag: - zeroconf_min_version = (0, 16, 0) + zeroconf_min_version = (0, 17, 0) zeroconf_version = tuple([int(num) for num in __zeroconf_version.split('.')]) logger.debug("Zeroconf version {0} detected.".format(__zeroconf_version)) if zeroconf_version < zeroconf_min_version: - logger.critical("Please install zeroconf 0.16 or higher.") + logger.critical("Please install zeroconf 0.17 or higher.") sys.exit(1) # Global var @@ -57,7 +53,7 @@ zeroconf_type = "_%s._tcp." % appname class AutoDiscovered(object): - """Class to manage the auto discovered servers dict""" + """Class to manage the auto discovered servers dict.""" def __init__(self): # server_dict is a list of dict (JSON compliant) @@ -65,30 +61,30 @@ class AutoDiscovered(object): self._server_list = [] def get_servers_list(self): - """Return the current server list (list of dict)""" + """Return the current server list (list of dict).""" return self._server_list def set_server(self, server_pos, key, value): - """Set the key to the value for the server_pos (position in the list)""" + """Set the key to the value for the server_pos (position in the list).""" self._server_list[server_pos][key] = value def add_server(self, name, ip, port): - """Add a new server to the list""" - new_server = {'key': name, # Zeroconf name with both hostname and port - 'name': name.split(':')[0], # Short name - 'ip': ip, # IP address seen by the client - 'port': port, # TCP port - 'username': 'glances', # Default username - 'password': '', # Default password - 'status': 'UNKNOWN', # Server status: 'UNKNOWN', 'OFFLINE', 'ONLINE', 'PROTECTED' - 'type': 'DYNAMIC', # Server type: 'STATIC' or 'DYNAMIC' - } + """Add a new server to the list.""" + new_server = { + 'key': name, # Zeroconf name with both hostname and port + 'name': name.split(':')[0], # Short name + 'ip': ip, # IP address seen by the client + 'port': port, # TCP port + 'username': 'glances', # Default username + 'password': '', # Default password + 'status': 'UNKNOWN', # Server status: 'UNKNOWN', 'OFFLINE', 'ONLINE', 'PROTECTED' + 'type': 'DYNAMIC'} # Server type: 'STATIC' or 'DYNAMIC' self._server_list.append(new_server) logger.debug("Updated servers list (%s servers): %s" % (len(self._server_list), self._server_list)) def remove_server(self, name): - """Remove a server from the dict""" + """Remove a server from the dict.""" for i in self._server_list: if i['key'] == name: try: @@ -103,22 +99,23 @@ class AutoDiscovered(object): class GlancesAutoDiscoverListener(object): - """Zeroconf listener for Glances server""" + """Zeroconf listener for Glances server.""" def __init__(self): # Create an instance of the servers list self.servers = AutoDiscovered() def get_servers_list(self): - """Return the current server list (list of dict)""" + """Return the current server list (list of dict).""" return self.servers.get_servers_list() def set_server(self, server_pos, key, value): - """Set the key to the value for the server_pos (position in the list)""" + """Set the key to the value for the server_pos (position in the list).""" self.servers.set_server(server_pos, key, value) def add_service(self, zeroconf, srv_type, srv_name): - """Method called when a new Zeroconf client is detected + """Method called when a new Zeroconf client is detected. + Return True if the zeroconf client is a Glances server Note: the return code will never be used """ @@ -141,7 +138,7 @@ class GlancesAutoDiscoverListener(object): return True def remove_service(self, zeroconf, srv_type, srv_name): - # Remove the server from the list + """Remove the server from the list.""" self.servers.remove_server(srv_name) logger.info( "Glances server %s removed from the autodetect list" % srv_name) @@ -149,7 +146,7 @@ class GlancesAutoDiscoverListener(object): class GlancesAutoDiscoverServer(object): - """Implementation of the Zeroconf protocol (server side for the Glances client)""" + """Implementation of the Zeroconf protocol (server side for the Glances client).""" def __init__(self, args=None): if zeroconf_tag: @@ -169,14 +166,14 @@ class GlancesAutoDiscoverServer(object): |