Merge branch 'issue1105' into develop

This commit is contained in:
nicolargo
2018-01-16 22:29:36 +01:00
4 changed files with 72 additions and 4 deletions

1
NEWS
View File

@@ -17,6 +17,7 @@ Enhancements and new features:
* Remove graph export from Glances #1206
* Add a code of conduct for Glances project's participants #1211
* Context switches bottleneck identification #1212
* Take advantage of the PSUtil issue #1025 (Add process_iter(attrs, ad_value)) #1105
Bugs corrected:

View File

@@ -21,6 +21,7 @@
import os
import shlex
import copy
from datetime import timedelta
from glances.compat import iteritems
@@ -80,7 +81,7 @@ class Plugin(GlancesPlugin):
self.nb_log_core = 0
# Get the max values (dict)
self.max_values = glances_processes.max_values()
self.max_values = copy.deepcopy(glances_processes.max_values())
# Get the maximum PID number
# Use to optimize space (see https://github.com/nicolargo/glances/issues/959)
@@ -111,7 +112,8 @@ class Plugin(GlancesPlugin):
self.stats = glances_processes.getlist()
# Get the max values (dict)
self.max_values = glances_processes.max_values()
# Use Deep copy to avoid change between update and display
self.max_values = copy.deepcopy(glances_processes.max_values())
elif self.input_method == 'snmp':
# No SNMP grab for processes
@@ -304,7 +306,8 @@ class Plugin(GlancesPlugin):
msg = '{:>10}'.format('?')
ret.append(self.curse_add_line(msg, optional=True))
# IO read/write
if 'io_counters' in p:
if 'io_counters' in p and p['io_counters'][4] == 1:
# Display rate if stats is available and io_tag ([4]) == 1
# IO read
io_rs = int((p['io_counters'][0] - p['io_counters'][2]) / p['time_since_update'])
if io_rs == 0:

View File

@@ -149,6 +149,8 @@ class GlancesProcesses(object):
return int(f.read())
except (OSError, IOError):
return None
else:
return None
@property
def max_processes(self):
@@ -401,6 +403,68 @@ class GlancesProcesses(object):
self.processlist = []
self.reset_processcount()
# Do not process if disable tag is set
if self.disable_tag:
return
# Grab the stats
mandatories_attr = ['cmdline', 'cpu_percent', 'cpu_times',
'io_counters', 'memory_info', 'memory_percent',
'name', 'nice', 'pid',
'ppid', 'status', 'username']
# and build the processes stats list
self.processlist = [p.info for p in sorted(psutil.process_iter(attrs=mandatories_attr,
ad_value=None),
key=lambda p: p.info['cpu_percent'])]
# Update the maximum process ID (pid) number
self.processcount['pid_max'] = self.pid_max
# Loop over processes and add metadata
for proc in self.processlist:
# Time since last update (for disk_io rate computation)
proc['time_since_update'] = getTimeSinceLastUpdate('process_disk')
# Process status (only keep the first char)
proc['status'] = str(proc['status'])[:1].upper()
# Process IO
# procstat['io_counters'] is a list:
# [read_bytes, write_bytes, read_bytes_old, write_bytes_old, io_tag]
# If io_tag = 0 > Access denied (display "?")
# If io_tag = 1 > No access denied (display the IO rate)
# Availability: all platforms except macOS and Illumos/Solaris
if proc['io_counters'] is not None:
io_new = [proc['io_counters'].read_bytes,
proc['io_counters'].write_bytes]
# For IO rate computation
# Append saved IO r/w bytes
try:
proc['io_counters'] = io_new + self.io_old[proc['pid']]
io_tag = 1
except KeyError:
proc['io_counters'] = io_new + [0, 0]
io_tag = 0
# then save the IO r/w bytes
self.io_old[proc['pid']] = io_new
else:
proc['io_counters'] = [0, 0] + [0, 0]
io_tag = 0
# Append the IO tag (for display)
proc['io_counters'] += [io_tag]
# Compute the maximum value for keys in self._max_values_list
# Compute max
for k in self._max_values_list:
self.set_max_values(k, max(i[k] for i in self.processlist))
def update_OLD(self):
"""Update the processes stats."""
# Reset the stats
self.processlist = []
self.reset_processcount()
# Do not process if disable tag is set
if self.disable_tag:
return

View File

@@ -1 +1 @@
psutil==5.2.2
psutil==5.4.2