Skip to content

Commit

Permalink
Correct monitor list, all processes are take into account (issue nico…
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Feb 6, 2015
1 parent 4778542 commit 79373b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
18 changes: 9 additions & 9 deletions glances/core/glances_monitor_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,11 @@ def update(self):
# Iter upon the monitored list
for i in range(0, len(self.get())):
# Search monitored processes by a regular expression
processlist = glances_processes.getlist()
processlist = glances_processes.getalllist()
monitoredlist = [p for p in processlist if re.search(self.regex(i), p['cmdline']) is not None]
self.__monitor_list[i]['count'] = len(monitoredlist)

if self.command(i) is None:
# If there is no command specified in the conf file
# then display CPU and MEM %
self.__monitor_list[i]['result'] = 'CPU: {0:.1f}% | MEM: {1:.1f}%'.format(
sum([p['cpu_percent'] for p in monitoredlist]),
sum([p['memory_percent'] for p in monitoredlist]))
continue
else:
if self.command(i) is not None:
# Execute the user command line
try:
self.__monitor_list[i]['result'] = subprocess.check_output(self.command(i),
Expand All @@ -148,6 +141,13 @@ def update(self):
except Exception:
self.__monitor_list[i]['result'] = _("Cannot execute command")

if self.command(i) is None or self.__monitor_list[i]['result'] == '':
# If there is no command specified in the conf file
# then display CPU and MEM %
self.__monitor_list[i]['result'] = 'CPU: {0:.1f}% | MEM: {1:.1f}%'.format(
sum([p['cpu_percent'] for p in monitoredlist]),
sum([p['memory_percent'] for p in monitoredlist]))

return self.__monitor_list

def get(self):
Expand Down
13 changes: 13 additions & 0 deletions glances/core/glances_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def __init__(self, cache_timeout=60):

# Init stats
self.resetsort()
self.allprocesslist = []
self.processlist = []
self.processcount = {
'total': 0, 'running': 0, 'sleeping': 0, 'thread': 0}
Expand Down Expand Up @@ -627,6 +628,7 @@ def update(self):
# Get all processes stats
processloop = processdict.items()
first = False

for i in processloop:
# Already existing mandatory stats
procstat = i[1]
Expand All @@ -647,6 +649,13 @@ def update(self):
# Next...
first = False

# Build the all processes list used by the minitored list
self.allprocesslist = processdict.values()

# logger.info("*"*120)
# logger.info("ALL=%s" % self.allprocesslist)
# logger.info("DIS=%s" % self.processlist)

# Clean internals caches if timeout is reached
if self.cache_timer.finished():
self.username_cache = {}
Expand All @@ -658,6 +667,10 @@ def getcount(self):
"""Get the number of processes."""
return self.processcount

def getalllist(self):
"""Get the allprocesslist."""
return self.allprocesslist

def getlist(self, sortedby=None):
"""Get the processlist."""
return self.processlist
Expand Down

0 comments on commit 79373b2

Please sign in to comment.