From 9c3f219f16ab705114c9d084f839841280e1b1bf Mon Sep 17 00:00:00 2001 From: Nicolas Hennion Date: Thu, 8 Aug 2013 23:07:15 +0200 Subject: [PATCH] Add default extended stat for monitored processes list --- glances/conf/glances-with-monitored.conf | 3 +++ glances/glances.py | 32 ++++++++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/glances/conf/glances-with-monitored.conf b/glances/conf/glances-with-monitored.conf index 7cf32228..c9caa71e 100644 --- a/glances/conf/glances-with-monitored.conf +++ b/glances/conf/glances-with-monitored.conf @@ -84,6 +84,9 @@ mem_critical=90 # * regex: regular expression of the processes to monitor # * command: (optional) full path to shell command/script for extended stat # Use with caution. Should return a single line string. +# Only execute when at least one process is running +# By default display CPU and MEM % +# Limitation: Do not use in client / server mode # * countmin: (optional) minimal number of processes # A warning will be displayed if number of process < count # * countmax: (optional) maximum number of processes diff --git a/glances/glances.py b/glances/glances.py index a6bc37d6..7f400e4b 100644 --- a/glances/glances.py +++ b/glances/glances.py @@ -19,7 +19,7 @@ # along with this program. If not, see . __appname__ = 'glances' -__version__ = "1.7RC3" +__version__ = "1.7RC4" __author__ = "Nicolas Hennion " __licence__ = "LGPL" @@ -3097,16 +3097,26 @@ class glancesScreen: monitors.countmin(item), monitors.countmax(item))) # Build and print optional message - if (monitors.command(item) != None): - try: - cmdret = subprocess.check_output(monitors.command(item), shell = True) - except subprocess.CalledProcessError: - cmdret = _("Error: ") + monitors.command(item) - except: - cmdret = _("Can not execute command") - monitormsg2 = "{0}".format(cmdret) - self.term_window.addnstr(monitor_y, self.process_x + 35, - monitormsg2, screen_x - process_x - 35) + if (len(monitoredlist) > 0): + if (monitors.command(item) != None): + # Execute the user command line + try: + cmdret = subprocess.check_output(monitors.command(item), shell = True) + except subprocess.CalledProcessError: + cmdret = _("Error: ") + monitors.command(item) + except: + cmdret = _("Can not execute command") + else: + # By default display CPU and MEM % + cmdret = "CPU: {0:.1f}% / MEM: {1:.1f}%".format( + sum([p['cpu_percent'] for p in monitoredlist]), + sum([p['memory_percent'] for p in monitoredlist])) + else: + cmdret = "" + + monitormsg2 = "{0}".format(cmdret) + self.term_window.addnstr(monitor_y, self.process_x + 35, + monitormsg2, screen_x - process_x - 35) # Generate log logs.add(self.__getMonitoredAlert(len(monitoredlist),