From e18be6cdfa868808c513c1c9fd6ac5991cb2e6e9 Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Wed, 14 Sep 2016 17:13:24 +0200 Subject: [PATCH] Do not highlight zero value on CPU and MEM processes list --- glances/plugins/glances_plugin.py | 16 ++++++++++++++-- glances/plugins/glances_processlist.py | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 6e78a56f..6c831d56 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -432,7 +432,13 @@ class GlancesPlugin(object): """Set the limits to input_limits.""" self._limits = input_limits - def get_alert(self, current=0, minimum=0, maximum=100, header="", log=False): + def get_alert(self, + current=0, + minimum=0, + maximum=100, + highlight_zero=True, + header="", + log=False): """Return the alert status relative to a current value. Use this function for minor stats. @@ -442,13 +448,19 @@ class GlancesPlugin(object): If current > WARNING of max then alert = WARNING If current > CRITICAL of max then alert = CRITICAL + If highlight=True than 0.0 is highlighted + If defined 'header' is added between the plugin name and the status. Only useful for stats with several alert status. If log=True than add log if necessary elif log=False than do not log - elig log=None than apply the config given in the conf file + elif log=None than apply the config given in the conf file """ + # Manage 0 (0.0) value if highlight_zero is not True + if not highlight_zero and current == 0: + return 'DEFAULT' + # Compute the % try: value = (current * 100) / maximum diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index d216d829..ae090c30 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -199,7 +199,7 @@ class Plugin(GlancesPlugin): else: msg = '{:>6.1f}'.format(p['cpu_percent']) ret.append(self.curse_add_line(msg, - self.get_alert(p['cpu_percent'], header="cpu"))) + self.get_alert(p['cpu_percent'], highlight_zero=False, header="cpu"))) else: msg = '{:>6}'.format('?') ret.append(self.curse_add_line(msg)) @@ -207,7 +207,7 @@ class Plugin(GlancesPlugin): if 'memory_percent' in p and p['memory_percent'] is not None and p['memory_percent'] != '': msg = '{:>6.1f}'.format(p['memory_percent']) ret.append(self.curse_add_line(msg, - self.get_alert(p['memory_percent'], header="mem"))) + self.get_alert(p['memory_percent'], highlight_zero=False, header="mem"))) else: msg = '{:>6}'.format('?') ret.append(self.curse_add_line(msg))