summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Hennion <nicolas@nicolargo.com>2020-07-20 08:53:29 +0200
committerGitHub <noreply@github.com>2020-07-20 08:53:29 +0200
commit64b85c32f0b8e8a9b729da1f67e8b3eed3a58753 (patch)
tree6a745b0a43a7f88c2da79ebe3bcdff4d2a9aa686
parentb0dc3ff54e04636cc5efba0d7600daaf5c1d9215 (diff)
parent09cfa64596004cdd637dc96f30aef6648ddd68ec (diff)
Merge pull request #1680 from HamiltonFintech/develop
Reflect "used percent" user disk space for [fs] alert
-rw-r--r--docs/aoa/actions.rst37
-rw-r--r--docs/aoa/fs.rst18
-rw-r--r--glances/plugins/glances_fs.py2
3 files changed, 45 insertions, 12 deletions
diff --git a/docs/aoa/actions.rst b/docs/aoa/actions.rst
index b83f1737..448d4fea 100644
--- a/docs/aoa/actions.rst
+++ b/docs/aoa/actions.rst
@@ -16,7 +16,9 @@ then add the ``_action`` line to the Glances configuration file:
critical_action=python /path/to/foo.py
All the stats are available in the command line through the use of the
-`{{mustache}}`_ syntax. Another example would be to create a log file
+`{{mustache}}`_ syntax. `Pystache`_ is required to render the mustache's template syntax.
+
+Another example would be to create a log file
containing used vs total disk space if a space trigger warning is
reached:
@@ -25,10 +27,40 @@ reached:
[fs]
warning=70
warning_action=echo {{mnt_point}} {{used}}/{{size}} > /tmp/fs.alert
+
+A last example would be to create a log file
+containing the total user disk space usage for a device and notify by email each time a space trigger critical is
+reached:
+
+.. code-block:: ini
+
+ [fs]
+ critical=90
+ critical_action_repeat=echo {{device_name}} {{percent}} > /tmp/fs.alert && python /etc/glances/actions.d/fs-critical.py
+
+Within ``/etc/glances/actions.d/fs-critical.py``:
+
+.. code-block:: python
+
+ import subprocess
+ from requests import get
+
+ fs_alert = open('/tmp/fs.alert', 'r').readline().strip().split(' ')
+ device = fs_alert[0]
+ percent = fs_alert[1]
+ system = subprocess.check_output(['uname', '-rn']).decode('utf-8').strip()
+ ip = get('https://api.ipify.org').text
+
+ body = 'Used user disk space for ' + device + ' is at ' + percent + '%.\nPlease cleanup the filesystem to clear the alert.\nServer: ' + str(system)+ '.\nIP address: ' + ip
+ ps = subprocess.Popen(('echo', '-e', body), stdout=subprocess.PIPE)
+ subprocess.call(['mail', '-s', 'CRITICAL: disk usage above 90%', '-r', 'postmaster@example.com', 'glances@example.com'], stdin=ps.stdout)
+
+
+
.. note::
You can use all the stats for the current plugin. See
- https://github.com/nicolargo/glances/wiki/The-Glances-2.x-API-How-to
+ https://github.com/nicolargo/glances/wiki/The-Glances-RESTFULL-JSON-API
for the stats list.
It is also possible to repeat action until the end of the alert.
@@ -42,3 +74,4 @@ use with caution:
critical_action_repeat=/home/myhome/bin/bipper.sh
.. _{{mustache}}: https://mustache.github.io/
+.. _Pystache: https://github.com/defunkt/pystache
diff --git a/docs/aoa/fs.rst b/docs/aoa/fs.rst
index 9ee0cc54..37dae695 100644
--- a/docs/aoa/fs.rst
+++ b/docs/aoa/fs.rst
@@ -8,18 +8,18 @@ File System
Glances displays the used and total file system disk space. The unit is
adapted dynamically.
-Alerts are set for used disk space.
+Alerts are set for `user disk space usage <https://psutil.readthedocs.io/en/latest/index.html?highlight=disk%20usage#psutil.disk_usage>`_.
Legend:
-=========== ============
-Disk usage Status
-=========== ============
-``<50%`` ``OK``
-``>50%`` ``CAREFUL``
-``>70%`` ``WARNING``
-``>90%`` ``CRITICAL``
-=========== ============
+===================== ============
+User disk space usage Status
+===================== ============
+``<50%`` ``OK``
+``>50%`` ``CAREFUL``
+``>70%`` ``WARNING``
+``>90%`` ``CRITICAL``
+===================== ============
.. note::
Limit values can be overwritten in the configuration file under
diff --git a/glances/plugins/glances_fs.py b/glances/plugins/glances_fs.py
index bc0a981d..6c1e618a 100644
--- a/glances/plugins/glances_fs.py
+++ b/glances/plugins/glances_fs.py
@@ -199,7 +199,7 @@ class Plugin(GlancesPlugin):
# Alert
for i in self.stats:
self.views[i[self.get_key()]]['used']['decoration'] = self.get_alert(
- i['used'], maximum=i['size'], header=i['mnt_point'])
+ current=i['size'] - i['free'], maximum=i['size'], header=i['mnt_point'])
def msg_curse(self, args=None, max_width=None):
"""Return the dict to display in the curse interface."""