mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-27 19:25:27 +03:00
Monitoring process list refactor into AMPs
This commit is contained in:
parent
92cb6e3407
commit
9999f558df
@ -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()
|
||||
|
@ -75,15 +75,13 @@ 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'))
|
||||
if res.ok:
|
||||
# u'Active connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n'
|
||||
self.set_result(res.text.rstrip())
|
||||
else:
|
||||
logger.debug('{0}: Can not grab status URL {1} ({2})'.format(self.NAME, self.get('status_url'), res.reason))
|
||||
# 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'))
|
||||
if res.ok:
|
||||
# u'Active connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n'
|
||||
self.set_result(res.text.rstrip())
|
||||
else:
|
||||
logger.debug('{0}: Can not grab status URL {1} ({2})'.format(self.NAME, self.get('status_url'), res.reason))
|
||||
|
||||
return self.result()
|
||||
|
@ -67,31 +67,29 @@ 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:
|
||||
res = check_output(self.get('systemctl_cmd').split())
|
||||
except OSError as e:
|
||||
logger.debug('{0}: Error while executing systemctl ({1})'.format(self.NAME, e))
|
||||
else:
|
||||
status = {}
|
||||
# For each line
|
||||
for r in res.split('\n')[1:-8]:
|
||||
# Split per space .*
|
||||
l = r.split()
|
||||
if len(l) > 3:
|
||||
# load column
|
||||
for c in range(1, 3):
|
||||
try:
|
||||
status[l[c]] += 1
|
||||
except KeyError:
|
||||
status[l[c]] = 1
|
||||
# Build the output (string) message
|
||||
output = 'Services\n'
|
||||
for k, v in iteritems(status):
|
||||
output += '{0}: {1}\n'.format(k, v)
|
||||
self.set_result(output, separator=' ')
|
||||
# Get the systemctl status
|
||||
logger.debug('{0}: Update stats using systemctl {1}'.format(self.NAME, self.get('systemctl_cmd')))
|
||||
try:
|
||||
res = check_output(self.get('systemctl_cmd').split())
|
||||
except OSError as e:
|
||||
logger.debug('{0}: Error while executing systemctl ({1})'.format(self.NAME, e))
|
||||
else:
|
||||
status = {}
|
||||
# For each line
|
||||
for r in res.split('\n')[1:-8]:
|
||||
# Split per space .*
|
||||
l = r.split()
|
||||
if len(l) > 3:
|
||||
# load column
|
||||
for c in range(1, 3):
|
||||
try:
|
||||
status[l[c]] += 1
|
||||
except KeyError:
|
||||
status[l[c]] = 1
|
||||
# Build the output (string) message
|
||||
output = 'Services\n'
|
||||
for k, v in iteritems(status):
|
||||
output += '{0}: {1}\n'.format(k, v)
|
||||
self.set_result(output, separator=' ')
|
||||
|
||||
return self.result()
|
||||
|
@ -66,32 +66,30 @@ 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:
|
||||
res = check_output(self.get('service_cmd').split(), stderr=STDOUT)
|
||||
except OSError as e:
|
||||
logger.debug('{0}: Error while executing service ({1})'.format(self.NAME, e))
|
||||
else:
|
||||
status = {'running': 0, 'stopped': 0, 'upstart': 0}
|
||||
# For each line
|
||||
for r in res.split('\n'):
|
||||
# Split per space .*
|
||||
l = r.split()
|
||||
if len(l) < 4:
|
||||
continue
|
||||
if l[1] == '+':
|
||||
status['running'] += 1
|
||||
elif l[1] == '-':
|
||||
status['stopped'] += 1
|
||||
elif l[1] == '?':
|
||||
status['upstart'] += 1
|
||||
# Build the output (string) message
|
||||
output = 'Services\n'
|
||||
for k, v in iteritems(status):
|
||||
output += '{0}: {1}\n'.format(k, v)
|
||||
self.set_result(output, separator=' ')
|
||||
# Get the systemctl status
|
||||
logger.debug('{0}: Update stats using service {1}'.format(self.NAME, self.get('service_cmd')))
|
||||
try:
|
||||
res = check_output(self.get('service_cmd').split(), stderr=STDOUT)
|
||||
except OSError as e:
|
||||
logger.debug('{0}: Error while executing service ({1})'.format(self.NAME, e))
|
||||
else:
|
||||
status = {'running': 0, 'stopped': 0, 'upstart': 0}
|
||||
# For each line
|
||||
for r in res.split('\n'):
|
||||
# Split per space .*
|
||||
l = r.split()
|
||||
if len(l) < 4:
|
||||
continue
|
||||
if l[1] == '+':
|
||||
status['running'] += 1
|
||||
elif l[1] == '-':
|
||||
status['stopped'] += 1
|
||||
elif l[1] == '?':
|
||||
status['upstart'] += 1
|
||||
# Build the output (string) message
|
||||
output = 'Services\n'
|
||||
for k, v in iteritems(status):
|
||||
output += '{0}: {1}\n'.format(k, v)
|
||||
self.set_result(output, separator=' ')
|
||||
|
||||
return self.result()
|
||||
|
@ -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
|
||||
|
||||
|
@ -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())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user