summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2020-07-21 10:26:40 +0200
committernicolargo <nicolas@nicolargo.com>2020-07-21 10:26:40 +0200
commit05897a61dd0a1da366e2f27231cbf0df19bebfb2 (patch)
tree4d96683b0c9d208b37ff23e6fd55dae12c73cccd
parent219c4de08f240320cae96e0a5a4a082db45a06da (diff)
Enhancement Request: .conf parameter for AMP #1690
-rw-r--r--conf/glances.conf3
-rw-r--r--docs/aoa/amps.rst14
-rw-r--r--glances/amps/glances_amp.py7
-rw-r--r--glances/amps_list.py8
-rw-r--r--glances/plugins/glances_amps.py6
5 files changed, 31 insertions, 7 deletions
diff --git a/conf/glances.conf b/conf/glances.conf
index 7ed466ae..50e4f425 100644
--- a/conf/glances.conf
+++ b/conf/glances.conf
@@ -572,8 +572,9 @@ countmax=20
[amp_conntrack]
# Use comma separated for multiple commands (no space around the comma)
+# If the regex key is not defined, the AMP will be executed every refresh second
+# and the process count will not be displayed (countmin and countmax will be ignore)
enable=false
-regex=\/sbin\/init
refresh=30
one_line=false
command=sysctl net.netfilter.nf_conntrack_count;sysctl net.netfilter.nf_conntrack_max
diff --git a/docs/aoa/amps.rst b/docs/aoa/amps.rst
index e32d6192..5de564ab 100644
--- a/docs/aoa/amps.rst
+++ b/docs/aoa/amps.rst
@@ -49,6 +49,20 @@ less than countmin):
.. image:: ../_static/amp-python-warning.png
+If the regex option is not defined, the AMP will be executed every refresh
+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
+
User defined AMP
----------------
diff --git a/glances/amps/glances_amp.py b/glances/amps/glances_amp.py
index 2ee89735..ccbee541 100644
--- a/glances/amps/glances_amp.py
+++ b/glances/amps/glances_amp.py
@@ -99,12 +99,11 @@ class GlancesAmp(object):
logger.debug("AMP - {}: Can not find section {} in the configuration file".format(self.NAME, self.amp_name))
return False
- # enable, regex and refresh are mandatories
- # if not configured then AMP is disabled
if self.enable():
- for k in ['regex', 'refresh']:
+ # Refresh option is mandatory
+ for k in ['refresh']:
if k not in self.configs:
- logger.warning("AMP - {}: Can not find configuration key {} in section {}".format(self.NAME, k, self.amp_name))
+ logger.warning("AMP - {}: Can not find configuration key {} in section {} (the AMP will be disabled)".format(self.NAME, k, self.amp_name))
self.configs['enable'] = 'false'
else:
logger.debug("AMP - {} is disabled".format(self.NAME))
diff --git a/glances/amps_list.py b/glances/amps_list.py
index a0b71d7d..1837aec4 100644
--- a/glances/amps_list.py
+++ b/glances/amps_list.py
@@ -112,6 +112,14 @@ class AmpsList(object):
if not v.enable():
# Do not update if the enable tag is set
continue
+
+ if v.regex() is None:
+ # If there is no regex, execute anyway (see issue #1690)
+ v.set_count(0)
+ # Call the AMP update method
+ thread = threading.Thread(target=v.update_wrapper, args=[[]])
+ thread.start()
+ continue
amps_list = self._build_amps_list(v, processlist)
diff --git a/glances/plugins/glances_amps.py b/glances/plugins/glances_amps.py
index 2e176ffa..4b4c0fa4 100644
--- a/glances/plugins/glances_amps.py
+++ b/glances/plugins/glances_amps.py
@@ -57,7 +57,9 @@ class Plugin(GlancesPlugin):
'timer': v.time_until_refresh(),
'count': v.count(),
'countmin': v.count_min(),
- 'countmax': v.count_max()})
+ 'countmax': v.count_max(),
+ 'regex': v.regex() is not None},
+ )
else:
# Not available in SNMP mode
pass
@@ -103,7 +105,7 @@ class Plugin(GlancesPlugin):
# Display AMP
first_column = '{}'.format(m['name'])
first_column_style = self.get_alert(m['count'], m['countmin'], m['countmax'])
- second_column = '{}'.format(m['count'])
+ second_column = '{}'.format(m['count'] if m['regex'] else '')
for l in m['result'].split('\n'):
# Display first column with the process name...
msg = '{:<16} '.format(first_column)