Monitoring process list refactor into AMPs

pull/863/head
nicolargo 2016-05-01 18:36:52 +02:00
parent 92cb6e3407
commit 9999f558df
6 changed files with 83 additions and 69 deletions

View File

@ -191,3 +191,13 @@ class GlancesAmp(object):
if ret is not None:
ret = u(ret)
return ret
def update_wrapper(self, process_list):
"""Wrapper for the children update"""
# Set the number of running process
self.set_count(len(process_list))
# Call the children update method
if self.should_update():
return self.update(process_list)
else:
return self.result()

View File

@ -75,8 +75,6 @@ class Amp(GlancesAmp):
def update(self, process_list):
"""Update the AMP"""
if self.should_update():
# Get the Nginx status
logger.debug('{0}: Update stats using status URL {1}'.format(self.NAME, self.get('status_url')))
res = requests.get(self.get('status_url'))

View File

@ -67,8 +67,6 @@ class Amp(GlancesAmp):
def update(self, process_list):
"""Update the AMP"""
if self.should_update():
# Get the systemctl status
logger.debug('{0}: Update stats using systemctl {1}'.format(self.NAME, self.get('systemctl_cmd')))
try:

View File

@ -66,8 +66,6 @@ class Amp(GlancesAmp):
def update(self, process_list):
"""Update the AMP"""
if self.should_update():
# Get the systemctl status
logger.debug('{0}: Update stats using service {1}'.format(self.NAME, self.get('service_cmd')))
try:

View File

@ -113,8 +113,14 @@ class AmpsList(object):
# At least one process is matching the regex
logger.debug("AMPS: {} process detected (PID={})".format(k, amps_list[0]['pid']))
# Call the AMP update method
thread = threading.Thread(target=v.update, args=[amps_list])
thread = threading.Thread(target=v.update_wrapper, args=[amps_list])
thread.start()
else:
# Set the process number to 0
v.set_count(0)
if v.count_min() > 0:
# Only display the "No running process message" is countmin is defined
v.set_result("No running process")
return self.__amps_dict

View File

@ -107,14 +107,18 @@ class Plugin(GlancesPlugin):
continue
# Display AMP
first_column = '{0}'.format(m['name'])
# first_column = '{0} {1}/{2}'.format(m['key'], int(m['timer']), int(m['refresh']))
first_column_style = self.get_alert(m['count'], m['countmin'], m['countmax'])
second_column = '{0}'.format(m['count'])
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, self.get_alert(m['count'], m['countmin'], m['countmax'])))
msg = '{0:<16} '.format(first_column)
ret.append(self.curse_add_line(msg, first_column_style))
# ... and second column with the number of matching processes...
msg = '{0:<4} '.format(second_column)
ret.append(self.curse_add_line(msg))
# ... only on the first line
first_column = ''
# Display AMP result in the second column
first_column = second_column = ''
# Display AMP result in the third column
ret.append(self.curse_add_line(l, splittable=True))
ret.append(self.curse_new_line())