提交 bdd55743 编写于 作者: N nicolargo

Allow comma separated commands in AMP

上级 f7f78f7d
......@@ -22,12 +22,13 @@ Bugs corrected:
* Too less data using prometheus exporter #1462
* Getting an error when running with prometheus exporter #1469
* Stack trace when starts Glances on CentOS #1470
* UnicodeEncodeError: 'ascii' codec can't encode character u'\u25cf' - Raspbian stretch #1483
* UnicodeEncodeError: 'ascii' codec can't encode character u'\u25cf' - Raspbian stretch #1483
Others:
* Documentation is unclear how to get Docker information #1386
* Add 'all' target to the Pip install (install all dependencies)
* Allow comma separated commands in AMP
Version 3.1
===========
......
......@@ -510,6 +510,14 @@ regex=.*python.*
refresh=3
countmax=20
[amp_conntrack]
# Use comma separated for multiple commands (no space around the comma)
enable=false
regex=\/sbin\/init
refresh=30
one_line=false
command=sysctl net.netfilter.nf_conntrack_count;sysctl net.netfilter.nf_conntrack_max
[amp_nginx]
# Use the NGinx AMP
# Nginx status page should be enable (https://easyengine.io/tutorials/nginx/status-page/)
......
......@@ -46,7 +46,7 @@ class Amp(GlancesAmp):
"""Glances' Default AMP."""
NAME = ''
VERSION = '1.0'
VERSION = '1.1'
DESCRIPTION = ''
AUTHOR = 'Nicolargo'
EMAIL = 'contact@nicolargo.com'
......@@ -59,23 +59,28 @@ class Amp(GlancesAmp):
def update(self, process_list):
"""Update the AMP"""
# Get the systemctl status
logger.debug('{}: Update AMP stats using service {}'.format(self.NAME, self.get('service_cmd')))
logger.debug('{}: Update AMP stats using command {}'.format(self.NAME, self.get('service_cmd')))
# Get command to execute
try:
res = self.get('command')
except OSError as e:
logger.debug('{}: Error while executing service ({})'.format(self.NAME, e))
else:
if res is not None:
try:
msg = u(check_output(res.split(), stderr=STDOUT))
self.set_result(to_ascii(msg.rstrip()))
except CalledProcessError as e:
self.set_result(e.output)
else:
# Set the default message if command return None
# Default sum of CPU and MEM for the matching regex
self.set_result('CPU: {:.1f}% | MEM: {:.1f}%'.format(
sum([p['cpu_percent'] for p in process_list]),
sum([p['memory_percent'] for p in process_list])))
logger.debug('{}: Error while executing command ({})'.format(self.NAME, e))
return self.result()
# No command found, use default message
if res is None:
# Set the default message if command return None
# Default sum of CPU and MEM for the matching regex
self.set_result('CPU: {:.1f}% | MEM: {:.1f}%'.format(
sum([p['cpu_percent'] for p in process_list]),
sum([p['memory_percent'] for p in process_list])))
return self.result()
# Run command(s)
# Comman separated commands can be executed
try:
msg = ''
for cmd in res.split(';'):
msg += u(check_output(cmd.split(), stderr=STDOUT))
self.set_result(to_ascii(msg.rstrip()))
except CalledProcessError as e:
self.set_result(e.output)
return self.result()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册