refactor: AMPs cleanup

pull/1962/head
RazCrimson 2021-11-28 16:30:54 +05:30
parent 1bbba2043c
commit 1c9ae9a86e
4 changed files with 15 additions and 13 deletions

View File

@ -47,7 +47,7 @@ class GlancesAmp(object):
EMAIL = '?' EMAIL = '?'
def __init__(self, name=None, args=None): def __init__(self, name=None, args=None):
"""Init AMP classe.""" """Init AMP class."""
logger.debug("AMP - Init {} version {}".format(self.NAME, self.VERSION)) logger.debug("AMP - Init {} version {}".format(self.NAME, self.VERSION))
# AMP name (= module name without glances_) # AMP name (= module name without glances_)
@ -69,7 +69,7 @@ class GlancesAmp(object):
def load_config(self, config): def load_config(self, config):
"""Load AMP parameters from the configuration file.""" """Load AMP parameters from the configuration file."""
# Read AMP confifuration. # Read AMP configuration.
# For ex, the AMP foo should have the following section: # For ex, the AMP foo should have the following section:
# #
# [foo] # [foo]
@ -77,12 +77,11 @@ class GlancesAmp(object):
# regex=\/usr\/bin\/nginx # regex=\/usr\/bin\/nginx
# refresh=60 # refresh=60
# #
# and optionnaly: # and optionally:
# #
# one_line=false # one_line=false
# option1=opt1 # option1=opt1
# ...
#
amp_section = 'amp_' + self.amp_name amp_section = 'amp_' + self.amp_name
if (hasattr(config, 'has_section') and if (hasattr(config, 'has_section') and
config.has_section(amp_section)): config.has_section(amp_section)):
@ -137,7 +136,7 @@ class GlancesAmp(object):
return self.get('refresh') return self.get('refresh')
def one_line(self): def one_line(self):
"""Return True|False if the AMP shoukd be displayed in oneline (one_lineline=true|false).""" """Return True|False if the AMP should be displayed in one line (one_line=true|false)."""
ret = self.get('one_line') ret = self.get('one_line')
if ret is None: if ret is None:
return False return False
@ -149,7 +148,9 @@ class GlancesAmp(object):
return self.timer.get() return self.timer.get()
def should_update(self): def should_update(self):
"""Return True is the AMP should be updated: """Return True is the AMP should be updated
Conditions for update:
- AMP is enable - AMP is enable
- only update every 'refresh' seconds - only update every 'refresh' seconds
""" """
@ -177,7 +178,8 @@ class GlancesAmp(object):
def set_result(self, result, separator=''): def set_result(self, result, separator=''):
"""Store the result (string) into the result key of the AMP """Store the result (string) into the result key of the AMP
if one_line is true then replace \n by separator
If one_line is true then it replaces `\n` by the separator
""" """
if self.one_line(): if self.one_line():
self.configs['result'] = u(result).replace('\n', separator) self.configs['result'] = u(result).replace('\n', separator)

View File

@ -21,7 +21,7 @@ r"""
Default AMP Default AMP
========= =========
Monitor a process by executing a command line. This is the default AMP's behavor Monitor a process by executing a command line. This is the default AMP's behavior
if no AMP script is found. if no AMP script is found.
Configuration file example Configuration file example
@ -75,7 +75,7 @@ class Amp(GlancesAmp):
sum([p['memory_percent'] for p in process_list]))) sum([p['memory_percent'] for p in process_list])))
return self.result() return self.result()
# Run command(s) # Run command(s)
# Comman separated commands can be executed # Comma separated commands can be executed
try: try:
msg = '' msg = ''
for cmd in res.split(';'): for cmd in res.split(';'):

View File

@ -26,8 +26,8 @@ Monitor the Nginx process using the status page.
How to read the stats How to read the stats
--------------------- ---------------------
Active connections Number of all open connections. This doesnt mean number of users. Active connections Number of all open connections. This doesn't mean number of users.
A single user, for a single pageview can open many concurrent connections to your server. A single user, for a single page-view can open many concurrent connections to your server.
Server accepts handled requests This shows three values. Server accepts handled requests This shows three values.
First is total accepted connections. First is total accepted connections.
Second is total handled connections. Usually first 2 values are same. Second is total handled connections. Usually first 2 values are same.

View File

@ -21,7 +21,7 @@ r"""
SystemV AMP SystemV AMP
=========== ===========
Monitor the state of the Syste V init system and service. Monitor the state of the System V init system and service.
How to read the stats How to read the stats
--------------------- ---------------------