summaryrefslogtreecommitdiffstats
path: root/glances/amps
diff options
context:
space:
mode:
authornicolargo <nicolashennion@gmail.com>2016-04-16 16:15:36 +0200
committernicolargo <nicolashennion@gmail.com>2016-04-16 16:15:36 +0200
commit5481771263216ad28abd694a41f247d53e24893d (patch)
treee0a0dabcdee3b5aa3c458bf94928895ed3d3527a /glances/amps
parent389423337581553edffcd9cdd0e6b2868b70765e (diff)
AMP Nginx OK
Diffstat (limited to 'glances/amps')
-rw-r--r--glances/amps/glances_amp.py19
-rw-r--r--glances/amps/glances_nginx.py18
2 files changed, 28 insertions, 9 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()