mirror of
https://github.com/nicolargo/glances.git
synced 2026-03-13 11:28:12 -04:00
First step for countmin / countmax
This commit is contained in:
@@ -253,10 +253,20 @@ queue=glances_queue
|
||||
|
||||
######
|
||||
# AMPS
|
||||
# * enable: Enable (true) or disable (false) the AMP
|
||||
# * regex: Regular expression to filter the process(es)
|
||||
# * refresh: The AMP is executed every refresh seconds
|
||||
# * one_line: (optional) Force (if true) the AMP to be displayed in one line
|
||||
* * command: (optional) command to execute when the process is detected (thk to the regex)
|
||||
# * countmin: (optional) minimal number of processes
|
||||
# A warning will be displayed if number of process < count
|
||||
# * countmax: (optional) maximum number of processes
|
||||
# A warning will be displayed if number of process > count
|
||||
# * <foo>: Others variables can be defined and used in the AMP script
|
||||
######
|
||||
|
||||
[amp_dropbox]
|
||||
# Use the default AMP which execute the command
|
||||
# Use the default AMP (no dedicated AMP Python script)
|
||||
enable=true
|
||||
regex=.*dropbox.*
|
||||
refresh=3
|
||||
@@ -264,6 +274,14 @@ one_line=false
|
||||
command=dropbox status
|
||||
countmin=1
|
||||
|
||||
[amp_xeyes]
|
||||
# Use the default AMP (no dedicated AMP Python script)
|
||||
enable=true
|
||||
regex=.*xeyes.*
|
||||
refresh=3
|
||||
countmin=1
|
||||
countmax=2
|
||||
|
||||
[amp_nginx]
|
||||
# Nginx status page should be enable (https://easyengine.io/tutorials/nginx/status-page/)
|
||||
enable=true
|
||||
|
||||
@@ -109,6 +109,9 @@ class GlancesAmp(object):
|
||||
else:
|
||||
logger.warning("{0} is disabled".format(self.NAME))
|
||||
|
||||
# Init the count to 0
|
||||
self.configs['count'] = 0
|
||||
|
||||
return self.enable()
|
||||
|
||||
def get(self, key):
|
||||
@@ -157,6 +160,22 @@ class GlancesAmp(object):
|
||||
return self.enable()
|
||||
return False
|
||||
|
||||
def set_count(self, count):
|
||||
"""Set the number of processes matching the regex"""
|
||||
self.configs['count'] = count
|
||||
|
||||
def count(self):
|
||||
"""Get the number of processes matching the regex"""
|
||||
return self.get('count')
|
||||
|
||||
def count_min(self):
|
||||
"""Get the minimum number of processes"""
|
||||
return self.get('countmin')
|
||||
|
||||
def count_max(self):
|
||||
"""Get the maximum number of processes"""
|
||||
return self.get('countmax')
|
||||
|
||||
def set_result(self, result, separator=''):
|
||||
"""Store the result (string) into the result key of the AMP
|
||||
if one_line is true then replace \n by separator
|
||||
|
||||
@@ -61,13 +61,36 @@ class Plugin(GlancesPlugin):
|
||||
'name': v.NAME,
|
||||
'result': v.result(),
|
||||
'refresh': v.refresh(),
|
||||
'timer': v.time_until_refresh()})
|
||||
'timer': v.time_until_refresh(),
|
||||
'count': v.count(),
|
||||
'countmin': v.count_min(),
|
||||
'countmax': v.count_max(),
|
||||
})
|
||||
else:
|
||||
# Not available in SNMP mode
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
||||
def get_alert(self, nbprocess=0, countmin=None, countmax=None, header="", log=False):
|
||||
"""Return the alert status relative to the process number."""
|
||||
if nbprocess is None:
|
||||
return 'OK'
|
||||
if countmin is None:
|
||||
countmin = nbprocess
|
||||
if countmax is None:
|
||||
countmax = nbprocess
|
||||
if nbprocess > 0:
|
||||
if int(countmin) <= int(nbprocess) <= int(countmax):
|
||||
return 'OK'
|
||||
else:
|
||||
return 'WARNING'
|
||||
else:
|
||||
if int(countmin) == 0:
|
||||
return 'OK'
|
||||
else:
|
||||
return 'CRITICAL'
|
||||
|
||||
def msg_curse(self, args=None):
|
||||
"""Return the dict to display in the curse interface."""
|
||||
# Init the return message
|
||||
@@ -88,7 +111,7 @@ class Plugin(GlancesPlugin):
|
||||
for l in m['result'].split('\n'):
|
||||
# Display first column with the process name...
|
||||
msg = '{0:<20} '.format(first_column)
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
ret.append(self.curse_add_line(msg, self.get_alert(m['count'], m['countmin'], m['countmax'])))
|
||||
# ... only on the first line
|
||||
first_column = ''
|
||||
# Display AMP result in the second column
|
||||
|
||||
Reference in New Issue
Block a user