AMP is now compatible with Glances client/server mode

This commit is contained in:
nicolargo 2016-04-24 17:51:55 +02:00
parent 5481771263
commit 83b098a16c
8 changed files with 41 additions and 20 deletions

View File

@ -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

View File

@ -17,13 +17,32 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""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'

View File

@ -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.")

View File

@ -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

View File

@ -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()

View File

@ -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)

View File

@ -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_"

View File

@ -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