mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-26 02:31:36 +03:00
AMP is now compatible with Glances client/server mode
This commit is contained in:
parent
5481771263
commit
83b098a16c
@ -83,7 +83,7 @@ class GlancesAmp(object):
|
|||||||
self.configs[param] = self.configs[param][0]
|
self.configs[param] = self.configs[param][0]
|
||||||
logger.debug("{0}: Load parameter: {1} = {2}".format(self.NAME, param, self.configs[param]))
|
logger.debug("{0}: Load parameter: {1} = {2}".format(self.NAME, param, self.configs[param]))
|
||||||
else:
|
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
|
# enable, regex and refresh are mandatories
|
||||||
# if not configured then AMP is disabled
|
# if not configured then AMP is disabled
|
||||||
|
@ -17,13 +17,32 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# 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/>.
|
# 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.
|
Nginx AMP
|
||||||
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).
|
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
|
import requests
|
||||||
@ -49,8 +68,8 @@ class Amp(GlancesAmp):
|
|||||||
"""Update the AMP"""
|
"""Update the AMP"""
|
||||||
|
|
||||||
if self.should_update():
|
if self.should_update():
|
||||||
logger.debug('{0}: Update stats using status URL {1}'.format(self.NAME, self.get('status_url')))
|
|
||||||
# Get the Nginx status
|
# 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'))
|
req = requests.get(self.get('status_url'))
|
||||||
if req.ok:
|
if req.ok:
|
||||||
# u'Active connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n'
|
# u'Active connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n'
|
||||||
|
@ -204,12 +204,16 @@ class GlancesAutoDiscoverClient(object):
|
|||||||
# Issue #528 (no network interface available)
|
# Issue #528 (no network interface available)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print("Announce the Glances server on the LAN (using {0} IP address)".format(zeroconf_bind_address))
|
|
||||||
self.info = ServiceInfo(
|
self.info = ServiceInfo(
|
||||||
zeroconf_type, '{0}:{1}.{2}'.format(hostname, args.port, zeroconf_type),
|
zeroconf_type, '{0}:{1}.{2}'.format(hostname, args.port, zeroconf_type),
|
||||||
address=socket.inet_aton(zeroconf_bind_address), port=args.port,
|
address=socket.inet_aton(zeroconf_bind_address), port=args.port,
|
||||||
weight=0, priority=0, properties={}, server=hostname)
|
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:
|
else:
|
||||||
logger.error("Cannot announce Glances server on the network: zeroconf library not found.")
|
logger.error("Cannot announce Glances server on the network: zeroconf library not found.")
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ class GlancesClient(object):
|
|||||||
logger.debug("Client version: {0} / Server version: {1}".format(__version__, client_version))
|
logger.debug("Client version: {0} / Server version: {1}".format(__version__, client_version))
|
||||||
else:
|
else:
|
||||||
self.log_and_exit("Client and server not compatible: \
|
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
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -151,6 +151,7 @@ class GlancesClient(object):
|
|||||||
if ret:
|
if ret:
|
||||||
# Load limits from the configuration file
|
# Load limits from the configuration file
|
||||||
# Each client can choose its owns limits
|
# Each client can choose its owns limits
|
||||||
|
logger.debug("Load limits from the client configuration file")
|
||||||
self.stats.load_limits(self.config)
|
self.stats.load_limits(self.config)
|
||||||
|
|
||||||
# Init screen
|
# Init screen
|
||||||
|
@ -723,12 +723,12 @@ class _GlancesCurses(object):
|
|||||||
self.new_column()
|
self.new_column()
|
||||||
self.new_line()
|
self.new_line()
|
||||||
self.display_plugin(stats_docker)
|
self.display_plugin(stats_docker)
|
||||||
if glances_processes.process_filter is None and cs_status is None:
|
if glances_processes.process_filter is None:
|
||||||
# Do not display stats monitor list and AMPS if a filter exist
|
# Do not display stats monitor list if a filter exist
|
||||||
self.new_line()
|
self.new_line()
|
||||||
self.display_plugin(stats_monitor)
|
self.display_plugin(stats_monitor)
|
||||||
self.new_line()
|
self.new_line()
|
||||||
self.display_plugin(stats_amps)
|
self.display_plugin(stats_amps)
|
||||||
self.new_line()
|
self.new_line()
|
||||||
self.display_plugin(stats_processcount)
|
self.display_plugin(stats_processcount)
|
||||||
self.new_line()
|
self.new_line()
|
||||||
|
@ -140,7 +140,7 @@ class GlancesStats(object):
|
|||||||
return [e for e in self._exports]
|
return [e for e in self._exports]
|
||||||
|
|
||||||
def load_limits(self, config=None):
|
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 each plugins, call the load_limits method
|
||||||
for p in self._plugins:
|
for p in self._plugins:
|
||||||
self._plugins[p].load_limits(config)
|
self._plugins[p].load_limits(config)
|
||||||
|
@ -32,7 +32,7 @@ class GlancesStatsClient(GlancesStats):
|
|||||||
|
|
||||||
def __init__(self, config=None, args=None):
|
def __init__(self, config=None, args=None):
|
||||||
"""Init the GlancesStatsClient class."""
|
"""Init the GlancesStatsClient class."""
|
||||||
super(GlancesStatsClient, self).__init__()
|
super(GlancesStatsClient, self).__init__(config=config, args=args)
|
||||||
|
|
||||||
# Init the configuration
|
# Init the configuration
|
||||||
self.config = config
|
self.config = config
|
||||||
@ -40,9 +40,6 @@ class GlancesStatsClient(GlancesStats):
|
|||||||
# Init the arguments
|
# Init the arguments
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
# Load AMPs, plugins and exports modules
|
|
||||||
self.load_modules(self.args)
|
|
||||||
|
|
||||||
def set_plugins(self, input_plugins):
|
def set_plugins(self, input_plugins):
|
||||||
"""Set the plugin list according to the Glances server."""
|
"""Set the plugin list according to the Glances server."""
|
||||||
header = "glances_"
|
header = "glances_"
|
||||||
|
@ -30,7 +30,7 @@ class GlancesStatsServer(GlancesStats):
|
|||||||
|
|
||||||
def __init__(self, config=None):
|
def __init__(self, config=None):
|
||||||
# Init the stats
|
# Init the stats
|
||||||
super(GlancesStatsServer, self).__init__(config)
|
super(GlancesStatsServer, self).__init__(config=config)
|
||||||
|
|
||||||
# Init the all_stats dict used by the server
|
# Init the all_stats dict used by the server
|
||||||
# all_stats is a dict of dicts filled by the server
|
# all_stats is a dict of dicts filled by the server
|
||||||
|
Loading…
Reference in New Issue
Block a user