mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-24 05:15:47 +03:00
Update doc for AMP
This commit is contained in:
parent
1621832567
commit
9c609ffdfd
5
NEWS
5
NEWS
@ -19,6 +19,11 @@ Bugs corrected:
|
||||
* [Web UI] Fix folders plugin never displayed (issue #829)
|
||||
* Correct issue IP plugin: VPN with no internet access (issue #842)
|
||||
|
||||
Deprecated:
|
||||
|
||||
* Python 2.6 is no longer supported
|
||||
* Monitoring process list module is replaced by AMP
|
||||
|
||||
Version 2.6.1
|
||||
=============
|
||||
|
||||
|
@ -253,19 +253,18 @@ queue=glances_queue
|
||||
|
||||
[amp_dropbox]
|
||||
# Use the default AMP (no dedicated AMP Python script)
|
||||
enable=true
|
||||
enable=false
|
||||
regex=.*dropbox.*
|
||||
refresh=3
|
||||
one_line=false
|
||||
command=dropbox status
|
||||
countmin=1
|
||||
|
||||
[amp_xeyes]
|
||||
# Use the default AMP (no dedicated AMP Python script)
|
||||
enable=true
|
||||
regex=.*xeyes.*
|
||||
[amp_python]
|
||||
# Monitor all Python scripts
|
||||
enable=false
|
||||
regex=.*python.*
|
||||
refresh=3
|
||||
countmin=1
|
||||
countmax=2
|
||||
|
||||
[amp_nginx]
|
||||
@ -291,9 +290,3 @@ regex=\/sbin\/init
|
||||
refresh=30
|
||||
one_line=true
|
||||
service_cmd=/usr/bin/service --status-all
|
||||
|
||||
[amp_python]
|
||||
# Monitor all Python scripts
|
||||
enable=true
|
||||
regex=.*python.*
|
||||
refresh=3
|
||||
|
BIN
docs/_static/amp-python-warning.png
vendored
Normal file
BIN
docs/_static/amp-python-warning.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
BIN
docs/_static/amp-python.png
vendored
Normal file
BIN
docs/_static/amp-python.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
BIN
docs/_static/amps-dropbox.png
vendored
Normal file
BIN
docs/_static/amps-dropbox.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
BIN
docs/_static/amps.png
vendored
BIN
docs/_static/amps.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 79 KiB |
101
docs/aoa/amps.rst
Normal file
101
docs/aoa/amps.rst
Normal file
@ -0,0 +1,101 @@
|
||||
.. _amps:
|
||||
|
||||
Applications Monitoring Process
|
||||
===============================
|
||||
|
||||
Thanks to Glances and it AMP module, you can add specific monitoring
|
||||
to running process. AMP are defined in the Glances configuration file.
|
||||
|
||||
You can disable AMP using the --disable-amps option or pressing the `A` shortkey.
|
||||
|
||||
Simple AMP
|
||||
----------
|
||||
|
||||
For example, a simple AMP which monitor the CPU/MEM of all Python processes
|
||||
can be define using:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[amp_python]
|
||||
enable=true
|
||||
regex=.*python.*
|
||||
refresh=3
|
||||
|
||||
Every 3 seconds (*refresh*) and if the *enable* key is true, Glances will
|
||||
filter the running processes list thanks to the .*python.* regular
|
||||
expression (*regex*). The default behavor for an AMP is to display:
|
||||
the number of matching processes, the CPU and MEM:
|
||||
|
||||
.. image:: ../_static/amp-python.png
|
||||
|
||||
You can also define the minimum (*countmin*) and/or maximum (*countmax*) process
|
||||
number. For example:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[amp_python]
|
||||
enable=true
|
||||
regex=.*python.*
|
||||
refresh=3
|
||||
countmin=1
|
||||
countmax=2
|
||||
|
||||
With this configuration, if the number of running Python script is higher than 2
|
||||
then the AMP is display with a purple color (red if < countmin):
|
||||
|
||||
.. image:: ../_static/amp-python-warning.png
|
||||
|
||||
User define AMP
|
||||
---------------
|
||||
|
||||
If you need to execute a specific command line, you can use the *command* option.
|
||||
For example, if you want to display the Dropbox process status, you can define the
|
||||
following section in the Glances configuration file:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[amp_dropbox]
|
||||
# Use the default AMP (no dedicated AMP Python script)
|
||||
enable=true
|
||||
regex=.*dropbox.*
|
||||
refresh=3
|
||||
one_line=false
|
||||
command=dropbox status
|
||||
countmin=1
|
||||
|
||||
The *dropbox status* command line will be executed and displayed in the Glances UI:
|
||||
|
||||
.. image:: ../_static/amp-python-dropbox.png
|
||||
|
||||
You can force Glances to display the result in one line setting the *one_line* to true.
|
||||
|
||||
Embeded AMP
|
||||
-----------
|
||||
|
||||
Glances provides some specifics AMP scripts (replacing the *command* line) hosted
|
||||
in the glances/amps folder. You can write your own AMP script to fill yours needs.
|
||||
AMP scripts are located in the glances/amps folder and should be names glances_*.py.
|
||||
An AMP script define an Amp class (GlancesAmp) with a mandatory update method.
|
||||
The update method 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).
|
||||
|
||||
You can write your owns AMP and enable its from the configuration file.
|
||||
The configuration file section should be named [amp_*].
|
||||
|
||||
For example, if you want to enable the Nginx AMP, the following definition
|
||||
should do the job (NGinx AMP is provided by the Glances team as an example):
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[amp_nginx]
|
||||
enable=true
|
||||
regex=\/usr\/sbin\/nginx
|
||||
refresh=60
|
||||
one_line=false
|
||||
status_url=http://localhost/nginx_status
|
||||
|
||||
Here is the result:
|
||||
|
||||
.. image:: ../_static/amps.png
|
||||
|
||||
In client/server mode, the AMP list is defined on the server side.
|
@ -3,63 +3,6 @@
|
||||
Monitored Processes List
|
||||
========================
|
||||
|
||||
The monitored processes list allows user, through the configuration
|
||||
file, to group processes and quickly show if the number of running
|
||||
processes is not good.
|
||||
The monitored processes list is deprecated.
|
||||
|
||||
.. image:: ../_static/monitored.png
|
||||
|
||||
Each item is defined by:
|
||||
|
||||
- ``description``: description of the processes (max 16 chars).
|
||||
- ``regex``: regular expression of the processes to monitor.
|
||||
- ``command``: (optional) full path to shell command/script for extended
|
||||
- stat. Should return a single line string. Use with caution.
|
||||
- ``countmin``: (optional) minimal number of processes. A warning will
|
||||
- be displayed if number of processes < count.
|
||||
- ``countmax``: (optional) maximum number of processes. A warning will
|
||||
be displayed if number of processes > count.
|
||||
|
||||
Up to ``10`` items can be defined.
|
||||
|
||||
For example, if you want to monitor the Nginx processes on a web server,
|
||||
the following definition should do the job:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[monitor]
|
||||
list_1_description=Nginx server
|
||||
list_1_regex=.*nginx.*
|
||||
list_1_command=nginx -v
|
||||
list_1_countmin=1
|
||||
list_1_countmax=4
|
||||
|
||||
If you also want to monitor the PHP-FPM daemon processes, you should add
|
||||
another item:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[monitor]
|
||||
list_1_description=Nginx server
|
||||
list_1_regex=.*nginx.*
|
||||
list_1_command=nginx -v
|
||||
list_1_countmin=1
|
||||
list_1_countmax=4
|
||||
list_2_description=PHP-FPM
|
||||
list_2_regex=.*php-fpm.*
|
||||
list_2_countmin=1
|
||||
list_2_countmax=20
|
||||
|
||||
In client/server mode, the list is defined on the server side.
|
||||
A new method, called `getAllMonitored`, is available in the APIs and
|
||||
get the JSON representation of the monitored processes list.
|
||||
|
||||
Alerts are set as following:
|
||||
|
||||
================= ============
|
||||
# of process Status
|
||||
================= ============
|
||||
``0`` ``CRITICAL``
|
||||
``min < p < max`` ``OK``
|
||||
``p > max`` ``WARNING``
|
||||
================= ============
|
||||
Please use the Application Monitoring Process (AMP).
|
||||
|
@ -95,11 +95,7 @@ Command-Line Options
|
||||
|
||||
disable process module
|
||||
|
||||
.. option:: --disable-monitor
|
||||
|
||||
disable monitoring process list module
|
||||
|
||||
.. option:: --disable-amp
|
||||
.. option:: --disable-amps
|
||||
|
||||
disable application monitoring process module
|
||||
|
||||
|
78
glances/amps/glances_default.py
Normal file
78
glances/amps/glances_default.py
Normal file
@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# This file is part of Glances.
|
||||
#
|
||||
# Copyright (C) 2016 Nicolargo <nicolas@nicolargo.com>
|
||||
#
|
||||
# Glances is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Glances is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
"""
|
||||
Default AMP
|
||||
=========
|
||||
|
||||
Monitor a process by executing a command line. This is the default AMP's behavor
|
||||
if no AMP script is found.
|
||||
|
||||
Configuration file example
|
||||
--------------------------
|
||||
|
||||
[amp_foo]
|
||||
enable=true
|
||||
regex=\/usr\/bin\/foo
|
||||
refresh=10
|
||||
one_line=false
|
||||
command=foo status
|
||||
"""
|
||||
|
||||
from subprocess import check_output, STDOUT
|
||||
|
||||
from glances.compat import u, to_ascii
|
||||
from glances.logger import logger
|
||||
from glances.amps.glances_amp import GlancesAmp
|
||||
|
||||
|
||||
class Amp(GlancesAmp):
|
||||
"""Glances' Default AMP."""
|
||||
|
||||
NAME = ''
|
||||
VERSION = '1.0'
|
||||
DESCRIPTION = ''
|
||||
AUTHOR = 'Nicolargo'
|
||||
EMAIL = 'contact@nicolargo.com'
|
||||
|
||||
def __init__(self, name=None, args=None):
|
||||
"""Init the AMP."""
|
||||
self.NAME = name.capitalize()
|
||||
super(Amp, self).__init__(name=name, args=args)
|
||||
|
||||
def update(self, process_list):
|
||||
"""Update the AMP"""
|
||||
# Get the systemctl status
|
||||
logger.debug('{0}: Update stats using service {1}'.format(self.NAME, self.get('service_cmd')))
|
||||
try:
|
||||
res = self.get('command')
|
||||
except OSError as e:
|
||||
logger.debug('{0}: Error while executing service ({1})'.format(self.NAME, e))
|
||||
else:
|
||||
if res is not None:
|
||||
msg = u(check_output(res.split(), stderr=STDOUT))
|
||||
self.set_result(to_ascii(msg.rstrip()))
|
||||
else:
|
||||
# Set the default message if command return None
|
||||
# Default sum of CPU and MEM for the matching regex
|
||||
self.set_result('CPU: {0:.1f}% | MEM: {1:.1f}%'.format(
|
||||
sum([p['cpu_percent'] for p in process_list]),
|
||||
sum([p['memory_percent'] for p in process_list])))
|
||||
|
||||
return self.result()
|
@ -138,8 +138,8 @@ Start the client browser (browser mode):\n\
|
||||
help='disable network, disk I/O, FS and sensors modules')
|
||||
parser.add_argument('--disable-process', action='store_true', default=False,
|
||||
dest='disable_process', help='disable process module')
|
||||
parser.add_argument('--disable-amp', action='store_true', default=False,
|
||||
dest='disable_amp', help='disable applications monitoring process (AMP) module')
|
||||
parser.add_argument('--disable-amps', action='store_true', default=False,
|
||||
dest='disable_amps', help='disable applications monitoring process (AMP) module')
|
||||
parser.add_argument('--disable-log', action='store_true', default=False,
|
||||
dest='disable_log', help='disable log module')
|
||||
parser.add_argument('--disable-bold', action='store_true', default=False,
|
||||
|
@ -330,7 +330,7 @@ class _GlancesCurses(object):
|
||||
glances_processes.sort_key = 'cpu_percent'
|
||||
elif self.pressedkey == ord('A'):
|
||||
# 'A' > enable/disable AMP module
|
||||
self.args.disable_amp = not self.args.disable_amp
|
||||
self.args.disable_amps = not self.args.disable_amps
|
||||
elif self.pressedkey == ord('b'):
|
||||
# 'b' > Switch between bit/s and Byte/s for network IO
|
||||
self.args.byte = not self.args.byte
|
||||
|
@ -59,7 +59,7 @@
|
||||
<section id="alert" class="plugin" ng-show="!arguments.disable_log" ng-include src="'plugins/alert.html'"></section>
|
||||
<div ng-show="!arguments.disable_process">
|
||||
<section id="processcount" class="plugin" ng-include src="'plugins/processcount.html'"></section>
|
||||
<div class="row">
|
||||
<div class="row" ng-if="!arguments.disable_amps">
|
||||
<div class="col-lg-18">
|
||||
<section id="amps" class="plugin" ng-include src="'plugins/amps.html'"></section>
|
||||
</div>
|
||||
|
@ -64,6 +64,10 @@ glancesApp.controller('statsController', function ($scope, $rootScope, $interval
|
||||
$scope.sorter.column = "cpu_percent";
|
||||
$scope.sorter.auto = true;
|
||||
break;
|
||||
case $event.shiftKey && $event.keyCode == keycodes.A:
|
||||
// D => Enable/disable AMPs
|
||||
$scope.arguments.disable_amps = !$scope.arguments.disable_amps;
|
||||
break;
|
||||
case !$event.shiftKey && $event.keyCode == keycodes.c:
|
||||
// c => Sort processes by CPU%
|
||||
$scope.sorter.column = "cpu_percent";
|
||||
|
@ -97,7 +97,7 @@ class Plugin(GlancesPlugin):
|
||||
# Only process if stats exist and display plugin enable...
|
||||
ret = []
|
||||
|
||||
if not self.stats or args.disable_process or args.disable_amp:
|
||||
if not self.stats or args.disable_process or args.disable_amps:
|
||||
return ret
|
||||
|
||||
# Build the string message
|
||||
|
Loading…
Reference in New Issue
Block a user