Add extended stats in the update finuntion of the glances_processes module

This commit is contained in:
Nicolargo 2014-08-06 19:30:26 +02:00
parent a9f4fa95e6
commit ecdafad8f0

View File

@ -84,8 +84,8 @@ class GlancesProcesses(object):
=> cpu_percent, memory_percent, io_counters, name
standard_stats: for all the displayed processes
=> username, cmdline, status, memory_info, cpu_times
extended_stats: only for top processes (!!! to be implemented)
=> connections (UDP/TCP), memory_swap
extended_stats: only for top processes (see issue #403)
=> connections (UDP/TCP), memory_swap...
"""
# Process ID (always)
@ -155,20 +155,39 @@ class GlancesProcesses(object):
procstat['status'] = str(procstat['status'])[:1].upper()
if extended_stats:
# Process network connections (TCP and UDP) (Experimental)
# CPU affinity
# Memory extended
# Number of context switch
# Number of file descriptors (Unix only)
# Threads number
procstat.update(proc.as_dict(attrs=['cpu_affinity',
'memory_info_ex',
'num_ctx_switches',
'num_fds',
'num_threads']))
# Number of handles (Windows only)
if is_windows:
procstat.update(proc.as_dict(attrs=['num_handles']))
# SWAP memory (Only on Linux based OS)
# http://www.cyberciti.biz/faq/linux-which-process-is-using-swap/
if is_linux:
try:
procstat['memory_swap'] = sum([v.swap for v in proc.memory_maps()])
except psutil.AccessDenied:
procstat['memory_swap'] = None
# Process network connections (TCP and UDP)
try:
procstat['tcp'] = len(proc.connections(kind="tcp"))
procstat['udp'] = len(proc.connections(kind="udp"))
except:
procstat['tcp'] = 0
procstat['udp'] = 0
procstat['tcp'] = None
procstat['udp'] = None
# SWAP memory
# Only on Linux based OS
# http://www.cyberciti.biz/faq/linux-which-process-is-using-swap/
if is_linux:
logger.debug(proc.memory_maps())
procstat['memory_swap'] = sum([ v.swap for v in proc.memory_maps() ])
# !!! Only for dev
logger.debug("EXTENDED STATS: %s" % procstat)
return procstat
@ -220,17 +239,22 @@ class GlancesProcesses(object):
# Sort the internal dict and cut the top N (Return a list of tuple)
# tuple=key (proc), dict (returned by __get_process_stats)
processiter = sorted(processdict.items(), key=lambda x: x[1][self.getsortkey()], reverse=True)
first = True
for i in processiter[0:self.get_max_processes()]:
# Already existing mandatory stats
procstat = i[1]
# Update with standard stats
# and extended stats but only for TOP (first) process
procstat.update(self.__get_process_stats(i[0],
mandatory_stats=False,
standard_stats=True))
standard_stats=True,
extended_stats=first))
# Add a specific time_since_update stats for bitrate
procstat['time_since_update'] = time_since_update
# Update process list
self.processlist.append(procstat)
# Next...
first = False
else:
# Get all the processes
for i in processdict.items():