Merge branch 'hotfix/issue1314'

This commit is contained in:
nicolargo 2018-09-04 23:15:55 +02:00
commit 9b29f15130
5 changed files with 43 additions and 14 deletions

7
NEWS
View File

@ -2,6 +2,13 @@
Glances Version 3
==============================================================================
Version 3.0.1
=============
Bug corrected:
* AMPs error if no output are provided by the system call #1314
Version 3.0
===========

View File

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "GLANCES" "1" "Sep 01, 2018" "3.0" "Glances"
.TH "GLANCES" "1" "Sep 04, 2018" "3.0.1" "Glances"
.SH NAME
glances \- An eye on your system
.

View File

@ -27,7 +27,7 @@ import signal
import sys
# Global name
__version__ = '3.0'
__version__ = '3.0.1'
__author__ = 'Nicolas Hennion <nicolas@nicolargo.com>'
__license__ = 'LGPLv3'

View File

@ -59,7 +59,7 @@ class Amp(GlancesAmp):
def update(self, process_list):
"""Update the AMP"""
# Get the systemctl status
logger.debug('{}: Update stats using service {}'.format(self.NAME, self.get('service_cmd')))
logger.debug('{}: Update AMP stats using service {}'.format(self.NAME, self.get('service_cmd')))
try:
res = self.get('command')
except OSError as e:

View File

@ -104,22 +104,17 @@ class AmpsList(object):
def update(self):
"""Update the command result attributed."""
# Search application monitored processes by a regular expression
# Get the current processes list (once)
processlist = glances_processes.getlist()
# Iter upon the AMPs dict
for k, v in iteritems(self.get()):
if not v.enable():
# Do not update if the enable tag is set
continue
try:
# Search in both cmdline and name (for kernel thread, see #1261)
amps_list = [p['pid'] for p in processlist
for c in p['cmdline']
if ((re.search(v.regex(), c) is not None) or
(re.search(v.regex(), p['name']) is not None))]
amps_list = list(set(amps_list))
except (TypeError, KeyError):
continue
amps_list = self._build_amps_list(v, processlist)
if len(amps_list) > 0:
# At least one process is matching the regex
logger.debug("AMPS: {} processes {} detected ({})".format(len(amps_list),
@ -132,11 +127,38 @@ class AmpsList(object):
# Set the process number to 0
v.set_count(0)
if v.count_min() is not None and v.count_min() > 0:
# Only display the "No running process message" is countmin is defined
# Only display the "No running process message" if countmin is defined
v.set_result("No running process")
return self.__amps_dict
def _build_amps_list(self, amp_value, processlist):
"""Return the AMPS process list according to the amp_value
Search application monitored processes by a regular expression
"""
ret = []
try:
# Search in both cmdline and name (for kernel thread, see #1261)
for p in processlist:
add_it = False
if (re.search(amp_value.regex(), p['name']) is not None):
add_it = True
else:
for c in p['cmdline']:
if (re.search(amp_value.regex(), c) is not None):
add_it = True
break
if add_it:
ret.append({'pid': p['pid'],
'cpu_percent': p['cpu_percent'],
'memory_percent': p['memory_percent']})
except (TypeError, KeyError) as e:
logger.debug("Can not build AMPS list ({})".format(e))
return ret
def getList(self):
"""Return the AMPs list."""
return listkeys(self.__amps_dict)