From 62132c16e21969cf48e77b2bd69cee0f48088f81 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 2 Nov 2019 09:42:28 +0100 Subject: [PATCH] Make processes.sort_key configurable #1536 --- conf/glances.conf | 4 ++++ glances/outputs/glances_curses.py | 15 --------------- glances/plugins/glances_processlist.py | 6 ++++++ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/conf/glances.conf b/conf/glances.conf index 7c953a7f..a69a1192 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -244,6 +244,10 @@ battery_critical=95 [processlist] disable=False +# Sort key: if not defined, the sort is automatically done by Glances (recommended) +# Should be one of the following: +# cpu_percent, memory_percent, io_counters, name, cpu_times, username +#sort_key=memory_percent # Define CPU/MEM (per process) thresholds in % # Default values if not defined: 50/70/90 cpu_careful=50 diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index 6e05d9f1..851aa70f 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -308,21 +308,6 @@ class _GlancesCurses(object): except Exception: pass - # def get_key(self, window): - # # Catch ESC key AND numlock key (issue #163) - # keycode = [0, 0] - # keycode[0] = window.getch() - # keycode[1] = window.getch() - # - # if keycode != [-1, -1]: - # logger.debug("Keypressed (code: %s)" % keycode) - # - # if keycode[0] == 27 and keycode[1] != -1: - # # Do not escape on specials keys - # return -1 - # else: - # return keycode[0] - def get_key(self, window): # @TODO: Check issue #163 ret = window.getch() diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index ede75415..859f8caa 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -116,6 +116,12 @@ class Plugin(GlancesPlugin): # Use to optimize space (see https://github.com/nicolargo/glances/issues/959) self.pid_max = glances_processes.pid_max + # Set the default sort key if it is defined in the configuration file + if 'processlist' in config.as_dict() and 'sort_key' in config.as_dict()['processlist']: + logger.debug('Configuration overwrites processes sort key by {}'.format(config.as_dict()['processlist']['sort_key'])) + self.auto_sort = False + self._sort_key = config.as_dict()['processlist']['sort_key'] + # Note: 'glances_processes' is already init in the processes.py script def get_key(self):