summaryrefslogtreecommitdiffstats
path: root/glances/amps
diff options
context:
space:
mode:
authornicolargo <nicolashennion@gmail.com>2016-04-15 15:05:32 +0200
committernicolargo <nicolashennion@gmail.com>2016-04-15 15:05:32 +0200
commit09d87e0a4e41f292843562bd624228e3ab1e6ba5 (patch)
tree31a6b70e80ccd37a8d58ac9382edcf97fabf9832 /glances/amps
parent8efb5e2ac8f9f257485d296609ac401c02bed8e4 (diff)
Regression on Monitoring list
Diffstat (limited to 'glances/amps')
-rw-r--r--glances/amps/glances_amp.py22
-rw-r--r--glances/amps/glances_nginx.py12
2 files changed, 28 insertions, 6 deletions
diff --git a/glances/amps/glances_amp.py b/glances/amps/glances_amp.py
index 1a95f68a..4dd9bb34 100644
--- a/glances/amps/glances_amp.py
+++ b/glances/amps/glances_amp.py
@@ -24,6 +24,7 @@ I am your father...
"""
from glances.compat import u
+from glances.timer import Timer
from glances.logger import logger
@@ -42,6 +43,10 @@ class GlancesAmp(object):
# Init the configs
self.configs = {}
+ # A timer is needed to only update every refresh seconds
+ # Init to 0 in order to update the AMP on startup
+ self.timer = Timer(0)
+
def load_config(self, config):
"""Load AMP parameters from the configuration file."""
@@ -55,7 +60,9 @@ class GlancesAmp(object):
#
# and optionnaly:
#
+ # one_line=false
# option1=opt1
+ # ...
#
if (hasattr(config, 'has_section') and
config.has_section(self.amp_name)):
@@ -100,12 +107,20 @@ class GlancesAmp(object):
"""Return refresh time in seconds for the current application monitoring process."""
return self.get('refresh')
+ def time_until_refresh(self):
+ """Return time in seconds until refresh."""
+ return self.timer.get()
+
def should_update(self):
"""Return True is the AMP should be updated:
- AMP is enable
- only update every 'refresh' seconds
"""
- return True
+ if self.timer.finished():
+ self.timer.set(self.refresh())
+ self.timer.reset()
+ return self.enable()
+ return False
def set_result(self, result):
"""Store the result (string) into the result key of the AMP"""
@@ -113,4 +128,7 @@ class GlancesAmp(object):
def result(self):
""" Return the result of the AMP (as a string)"""
- return u(self.get('result'))
+ ret = self.get('result')
+ if ret is not None:
+ ret = u(ret)
+ return ret
diff --git a/glances/amps/glances_nginx.py b/glances/amps/glances_nginx.py
index 33b49309..1cc80026 100644
--- a/glances/amps/glances_nginx.py
+++ b/glances/amps/glances_nginx.py
@@ -29,19 +29,23 @@ class Amp(GlancesAmp):
"""Glances' Nginx AMP."""
- def __init__(self, args=None):
- """Init the AMP."""
- super(Amp, self).__init__(args=args)
+ # def __init__(self, args=None):
+ # """Init the AMP."""
+ # super(Amp, self).__init__(args=args)
def update(self):
"""Update the AMP"""
if self.should_update():
logger.debug('AMPS: Update {0} using status URL {1}'.format(self.amp_name, self.get('status_url')))
+ # Get the Nginx status
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'
- self.set_result(req.text)
+ if self.get('one_line') is not None and self.get('one_line').lower() == 'true':
+ self.set_result(req.text.replace('\n', ''))
+ else:
+ self.set_result(req.text)
else:
logger.debug('AMPS: Can not grab status URL {0} ({1})'.format(self.get('status_url'), req.reason))