mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-25 02:02:32 +03:00
Allow comma separated commands in AMP
This commit is contained in:
parent
f7f78f7d1c
commit
bdd557437a
3
NEWS
3
NEWS
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user