From 5481771263216ad28abd694a41f247d53e24893d Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 16 Apr 2016 16:15:36 +0200 Subject: [PATCH] AMP Nginx OK --- glances/amps/glances_amp.py | 19 +++++++++++++------ glances/amps/glances_nginx.py | 18 +++++++++++++++--- glances/plugins/glances_amps.py | 4 ++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/glances/amps/glances_amp.py b/glances/amps/glances_amp.py index 4dd9bb34..e46f5b77 100644 --- a/glances/amps/glances_amp.py +++ b/glances/amps/glances_amp.py @@ -29,11 +29,18 @@ from glances.logger import logger class GlancesAmp(object): - """Main class for Glances AMP.""" + NAME = '?' + VERSION = '?' + DESCRIPTION = '?' + AUTHOR = '?' + EMAIL = '?' + def __init__(self, args=None): """Init AMP classe.""" + logger.debug("Init {0} version {1}".format(self.NAME, self.VERSION)) + # AMP name (= module name without glances_) self.amp_name = self.__class__.__module__[len('glances_'):] @@ -66,7 +73,7 @@ class GlancesAmp(object): # if (hasattr(config, 'has_section') and config.has_section(self.amp_name)): - logger.debug("AMP: Load {0} configuration".format(self.amp_name)) + logger.debug("{0}: Load configuration".format(self.NAME)) for param, _ in config.items(self.amp_name): try: self.configs[param] = config.get_float_value(self.amp_name, param) @@ -74,19 +81,19 @@ class GlancesAmp(object): self.configs[param] = config.get_value(self.amp_name, param).split(',') if len(self.configs[param]) == 1: self.configs[param] = self.configs[param][0] - logger.debug("AMP: Load {0} parameter: {1} = {2}".format(self.amp_name, param, self.configs[param])) + logger.debug("{0}: Load parameter: {1} = {2}".format(self.NAME, param, self.configs[param])) else: - logger.warning("AMP: Can not find section {0} in the configuration file".format(self.amp_name)) + logger.warning("{0}: Can not find section {1} in the configuration file".format(self.NAME, self.amp_name)) # enable, regex and refresh are mandatories # if not configured then AMP is disabled for k in ['enable', 'regex', 'refresh']: if k not in self.configs: - logger.warning("AMP: Can not find configuration key {0} in section {1}".format(k, self.amp_name)) + logger.warning("{0}: Can not find configuration key {1} in section {2}".format(self.NAME, k, self.amp_name)) self.configs['enable'] = 'false' if not self.enable(): - logger.warning("AMP: {0} is disabled".format(self.amp_name)) + logger.warning("{0} is disabled".format(self.NAME)) def get(self, key): """Generic method to get the item in the AMP configuration""" diff --git a/glances/amps/glances_nginx.py b/glances/amps/glances_nginx.py index 1cc80026..9c2cb9e3 100644 --- a/glances/amps/glances_nginx.py +++ b/glances/amps/glances_nginx.py @@ -19,6 +19,13 @@ """Nginx AMP.""" +""" +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). +""" + import requests from glances.logger import logger @@ -26,9 +33,14 @@ from glances.amps.glances_amp import GlancesAmp class Amp(GlancesAmp): - """Glances' Nginx AMP.""" + NAME = 'Nginx Glances AMP' + VERSION = '1.0' + DESCRIPTION = 'Get Nginx stats from status-page' + AUTHOR = 'Nicolargo' + EMAIL = 'contact@nicolargo.com' + # def __init__(self, args=None): # """Init the AMP.""" # super(Amp, self).__init__(args=args) @@ -37,7 +49,7 @@ class Amp(GlancesAmp): """Update the AMP""" if self.should_update(): - logger.debug('AMPS: Update {0} using status URL {1}'.format(self.amp_name, self.get('status_url'))) + logger.debug('{0}: Update stats using status URL {1}'.format(self.NAME, self.get('status_url'))) # Get the Nginx status req = requests.get(self.get('status_url')) if req.ok: @@ -47,6 +59,6 @@ class Amp(GlancesAmp): else: self.set_result(req.text) else: - logger.debug('AMPS: Can not grab status URL {0} ({1})'.format(self.get('status_url'), req.reason)) + logger.debug('{0}: Can not grab status URL {1} ({2})'.format(self.NAME, self.get('status_url'), req.reason)) return self.result() diff --git a/glances/plugins/glances_amps.py b/glances/plugins/glances_amps.py index 0672621b..5a47b84d 100644 --- a/glances/plugins/glances_amps.py +++ b/glances/plugins/glances_amps.py @@ -78,12 +78,12 @@ class Plugin(GlancesPlugin): # Build the string message for m in self.stats: + # Only display AMP if a result exist if m['result'] is None: - # Only display AMP if a result exist continue # Display AMP - # first_column = '{0} {1}/{2}'.format(m['key'], int(m['timer']), int(m['refresh'])) first_column = '{0}'.format(m['key']) + # first_column = '{0} {1}/{2}'.format(m['key'], int(m['timer']), int(m['refresh'])) for l in m['result'].split('\n'): # Display first column with the process name... msg = '{0:<20} '.format(first_column)