glances/docs/aoa/amps.rst

143 lines
3.6 KiB
ReStructuredText
Raw Normal View History

2016-05-02 11:32:46 +03:00
.. _amps:
Applications Monitoring Process
===============================
2017-03-12 20:52:17 +03:00
Thanks to Glances and its AMP module, you can add specific monitoring to
running processes. AMPs are defined in the Glances :ref:`configuration file<config>`.
2016-05-02 11:32:46 +03:00
You can disable AMP using the ``--disable-plugin amps`` option or pressing the
2017-03-12 20:52:17 +03:00
``A`` key.
2016-05-02 11:32:46 +03:00
Simple AMP
----------
2017-03-12 20:52:17 +03:00
For example, a simple AMP that monitor the CPU/MEM of all Python
processes can be defined as follows:
2016-05-02 11:32:46 +03:00
.. code-block:: ini
[amp_python]
enable=true
regex=.*python.*
refresh=3
2017-03-12 20:52:17 +03:00
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 behavior for an AMP is to display the number of matching
processes, CPU and MEM:
2016-05-02 11:32:46 +03:00
.. image:: ../_static/amp-python.png
2017-03-12 20:52:17 +03:00
You can also define the minimum (``countmin``) and/or maximum
(``countmax``) process number. For example:
2016-05-02 11:32:46 +03:00
.. code-block:: ini
[amp_python]
enable=true
regex=.*python.*
refresh=3
countmin=1
countmax=2
2017-03-12 20:52:17 +03:00
With this configuration, if the number of running Python scripts is
higher than 2, then the AMP is displayed with a purple color (red if
less than countmin):
2016-05-02 11:32:46 +03:00
.. image:: ../_static/amp-python-warning.png
If the regex option is not defined, the AMP will be executed every refresh
2022-04-10 16:50:39 +03:00
time and the process count will not be displayed (countmin and countmax will
be ignored).
For example:
.. code-block:: ini
[amp_conntrack]
enable=false
refresh=30
one_line=false
command=sysctl net.netfilter.nf_conntrack_count;sysctl net.netfilter.nf_conntrack_max
2022-04-10 16:50:39 +03:00
For security reason, pipe is not directly allowed in a AMP command but you create a sheel
script with your command:
.. code-block:: ini
$ cat /usr/local/bin/mycommand.sh
#!/bin/sh
ps -aux | wc -l
and use it in the amps:
.. code-block:: ini
[amp_amptest]
enable=true
regex=.*
refresh=15
one_line=false
command=/usr/local/bin/mycommand.sh
2017-03-12 20:52:17 +03:00
User defined AMP
----------------
2016-05-02 11:32:46 +03:00
2017-03-12 20:52:17 +03:00
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:
2016-05-02 11:32:46 +03:00
.. 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
2017-03-12 20:52:17 +03:00
The ``dropbox status`` command line will be executed and displayed in
the Glances UI:
2016-05-02 11:32:46 +03:00
2016-05-02 11:45:04 +03:00
.. image:: ../_static/amp-dropbox.png
2016-05-02 11:32:46 +03:00
2017-03-12 20:52:17 +03:00
You can force Glances to display the result in one line setting
``one_line`` to true.
2016-05-02 11:32:46 +03:00
2017-03-12 20:52:17 +03:00
Embedded AMP
------------
2016-05-02 11:32:46 +03:00
2017-03-12 20:52:17 +03:00
Glances provides some specific AMP scripts (replacing the ``command``
line). You can write your own AMP script to fill your needs. AMP scripts
are located in the ``amps`` folder and should be named ``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). To enable it, the configuration file section
should be named ``[amp_*]``.
2016-05-02 11:32:46 +03:00
2017-03-12 20:52:17 +03:00
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):
2016-05-02 11:32:46 +03:00
.. code-block:: ini
[amp_nginx]
enable=true
regex=\/usr\/sbin\/nginx
refresh=60
one_line=false
status_url=http://localhost/nginx_status
2017-03-12 20:52:17 +03:00
Here's the result:
2016-05-02 11:32:46 +03:00
.. image:: ../_static/amps.png
In client/server mode, the AMP list is defined on the server side.