Export individual processes stats - Export dict are now sorted #794

This commit is contained in:
nicolargo 2024-04-24 12:28:48 +02:00
parent 75b06ed4b1
commit c2fe2de355
2 changed files with 11 additions and 15 deletions

View File

@ -183,7 +183,7 @@ class GlancesExport(object):
else:
pre_key = ''
# Walk through the dict
for key, value in iteritems(stats):
for key, value in sorted(iteritems(stats)):
if isinstance(value, bool):
value = json_dumps(value)
if isinstance(value, list):

View File

@ -42,11 +42,6 @@ class GlancesProcesses(object):
# Should be set by the set_args method
self.args = None
# Add internals caches because psutil do not cache all the stats
# See: https://github.com/giampaolo/psutil/issues/462
self.username_cache = {}
self.cmdline_cache = {}
# The internals caches will be cleaned each 'cache_timeout' seconds
self.cache_timeout = cache_timeout
# First iteration, no cache
@ -363,14 +358,14 @@ class GlancesProcesses(object):
def is_selected_extended_process(self, position):
"""Return True if the process is the selected one for extended stats."""
return (
hasattr(self.args, 'programs')
and not self.args.programs
and hasattr(self.args, 'enable_process_extended')
and self.args.enable_process_extended
and not self.disable_extended_tag
and hasattr(self.args, 'cursor_position')
and position == self.args.cursor_position
and not self.args.disable_cursor
hasattr(self.args, 'programs') and
not self.args.programs and
hasattr(self.args, 'enable_process_extended') and
self.args.enable_process_extended and
not self.disable_extended_tag and
hasattr(self.args, 'cursor_position') and
position == self.args.cursor_position and
not self.args.disable_cursor
)
def update(self):
@ -389,7 +384,8 @@ class GlancesProcesses(object):
#####################
sorted_attrs = ['cpu_percent', 'cpu_times', 'memory_percent', 'name', 'status', 'num_threads']
displayed_attr = ['memory_info', 'nice', 'pid']
# 'name' can not be cached because it is used for filtering
# The following attributes are cached and only retreive every self.cache_timeout seconds
# Warning: 'name' can not be cached because it is used for filtering
cached_attrs = ['cmdline', 'username']
# Some stats are optional