From 83b098a16c1c6ef7e99d6cf21cfca09dfb2ece7c Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 24 Apr 2016 17:51:55 +0200 Subject: [PATCH] AMP is now compatible with Glances client/server mode --- glances/amps/glances_amp.py | 2 +- glances/amps/glances_nginx.py | 31 +++++++++++++++++++++++++------ glances/autodiscover.py | 8 ++++++-- glances/client.py | 3 ++- glances/outputs/glances_curses.py | 8 ++++---- glances/stats.py | 2 +- glances/stats_client.py | 5 +---- glances/stats_server.py | 2 +- 8 files changed, 41 insertions(+), 20 deletions(-) diff --git a/glances/amps/glances_amp.py b/glances/amps/glances_amp.py index e46f5b77..f3395d42 100644 --- a/glances/amps/glances_amp.py +++ b/glances/amps/glances_amp.py @@ -83,7 +83,7 @@ class GlancesAmp(object): self.configs[param] = self.configs[param][0] logger.debug("{0}: Load parameter: {1} = {2}".format(self.NAME, param, self.configs[param])) else: - logger.warning("{0}: Can not find section {1} in the configuration file".format(self.NAME, self.amp_name)) + logger.warning("{0}: Can not find section {1} in the configuration file {2}".format(self.NAME, self.amp_name, config)) # enable, regex and refresh are mandatories # if not configured then AMP is disabled diff --git a/glances/amps/glances_nginx.py b/glances/amps/glances_nginx.py index 9c2cb9e3..b43da089 100644 --- a/glances/amps/glances_nginx.py +++ b/glances/amps/glances_nginx.py @@ -17,13 +17,32 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -"""Nginx AMP.""" +""" +AMP (Application Monitoring Process) +A Glances AMP is a Python script called (every *refresh* seconds) if: +- the AMP is *enabled* in the Glances configuration file +- a process is running (match the *regex* define in the configuration file) +The script should define a Amp (GlancesAmp) class with, at least, an update method. +The update method should call the set_result method to set the AMP return string. +The return string is a string with one or more line (\n between lines). +If the *one_line* var is true then the AMP will be displayed in one line. +""" """ -A Glances AMP is a Python script called if a process is running. -The script should define a Amp (GlancesAmp) class with an update method. -The update method should call the set_result method to fill the AMP return string. -The return string is a string with one or more line (\n between lines). +Nginx AMP +========= + +Monitor the Nginx process using the status page + +Configuration file example: + +[nginx] +# Nginx status page should be enable (https://easyengine.io/tutorials/nginx/status-page/) +enable=true +regex=\/usr\/sbin\/nginx +refresh=60 +one_line=false +status_url=http://localhost/nginx_status """ import requests @@ -49,8 +68,8 @@ class Amp(GlancesAmp): """Update the AMP""" if self.should_update(): - logger.debug('{0}: Update stats using status URL {1}'.format(self.NAME, self.get('status_url'))) # Get the Nginx status + logger.debug('{0}: Update stats using status URL {1}'.format(self.NAME, self.get('status_url'))) req = requests.get(self.get('status_url')) if req.ok: # u'Active connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n' diff --git a/glances/autodiscover.py b/glances/autodiscover.py index b2f2fcb9..23486000 100644 --- a/glances/autodiscover.py +++ b/glances/autodiscover.py @@ -204,12 +204,16 @@ class GlancesAutoDiscoverClient(object): # Issue #528 (no network interface available) pass - print("Announce the Glances server on the LAN (using {0} IP address)".format(zeroconf_bind_address)) self.info = ServiceInfo( zeroconf_type, '{0}:{1}.{2}'.format(hostname, args.port, zeroconf_type), address=socket.inet_aton(zeroconf_bind_address), port=args.port, weight=0, priority=0, properties={}, server=hostname) - self.zeroconf.register_service(self.info) + try: + self.zeroconf.register_service(self.info) + except socket.error as e: + logger.error("Error while announcing Glances server: {0}".format(e)) + else: + print("Announce the Glances server on the LAN (using {0} IP address)".format(zeroconf_bind_address)) else: logger.error("Cannot announce Glances server on the network: zeroconf library not found.") diff --git a/glances/client.py b/glances/client.py index a1e68e0b..e93ec4ee 100644 --- a/glances/client.py +++ b/glances/client.py @@ -129,7 +129,7 @@ class GlancesClient(object): logger.debug("Client version: {0} / Server version: {1}".format(__version__, client_version)) else: self.log_and_exit("Client and server not compatible: \ - Client version: {0} / Server version: {1}".format(version, client_version)) + Client version: {0} / Server version: {1}".format(__version__, client_version)) return False else: @@ -151,6 +151,7 @@ class GlancesClient(object): if ret: # Load limits from the configuration file # Each client can choose its owns limits + logger.debug("Load limits from the client configuration file") self.stats.load_limits(self.config) # Init screen diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index d04818f8..1a67c677 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -723,12 +723,12 @@ class _GlancesCurses(object): self.new_column() self.new_line() self.display_plugin(stats_docker) - if glances_processes.process_filter is None and cs_status is None: - # Do not display stats monitor list and AMPS if a filter exist + if glances_processes.process_filter is None: + # Do not display stats monitor list if a filter exist self.new_line() self.display_plugin(stats_monitor) - self.new_line() - self.display_plugin(stats_amps) + self.new_line() + self.display_plugin(stats_amps) self.new_line() self.display_plugin(stats_processcount) self.new_line() diff --git a/glances/stats.py b/glances/stats.py index bf83fec9..be20d457 100644 --- a/glances/stats.py +++ b/glances/stats.py @@ -140,7 +140,7 @@ class GlancesStats(object): return [e for e in self._exports] def load_limits(self, config=None): - """Load the stats limits.""" + """Load the stats limits (except the one in the exclude list).""" # For each plugins, call the load_limits method for p in self._plugins: self._plugins[p].load_limits(config) diff --git a/glances/stats_client.py b/glances/stats_client.py index ad6a6370..2cd4a9e4 100644 --- a/glances/stats_client.py +++ b/glances/stats_client.py @@ -32,7 +32,7 @@ class GlancesStatsClient(GlancesStats): def __init__(self, config=None, args=None): """Init the GlancesStatsClient class.""" - super(GlancesStatsClient, self).__init__() + super(GlancesStatsClient, self).__init__(config=config, args=args) # Init the configuration self.config = config @@ -40,9 +40,6 @@ class GlancesStatsClient(GlancesStats): # Init the arguments self.args = args - # Load AMPs, plugins and exports modules - self.load_modules(self.args) - def set_plugins(self, input_plugins): """Set the plugin list according to the Glances server.""" header = "glances_" diff --git a/glances/stats_server.py b/glances/stats_server.py index 5d2a4384..86f5d3dc 100644 --- a/glances/stats_server.py +++ b/glances/stats_server.py @@ -30,7 +30,7 @@ class GlancesStatsServer(GlancesStats): def __init__(self, config=None): # Init the stats - super(GlancesStatsServer, self).__init__(config) + super(GlancesStatsServer, self).__init__(config=config) # Init the all_stats dict used by the server # all_stats is a dict of dicts filled by the server