From da0f59d2542aad483a7ac509ff96b9c4d2950646 Mon Sep 17 00:00:00 2001 From: Adrien Beudin Date: Tue, 16 Oct 2012 17:52:39 +0200 Subject: [PATCH] add process count --- parse_args | 5 +++++ yunohost_monitor.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/parse_args b/parse_args index abeadd6a..6feebbb8 100755 --- a/parse_args +++ b/parse_args @@ -469,6 +469,11 @@ action_map = { 'full' : '--uptime', 'help' : _("Show Uptime"), 'action' : 'store_true', + }, + '-p' : { + 'full' : '--process', + 'help' : _("Show Process Account"), + 'action' : 'store_true', }, } }, diff --git a/yunohost_monitor.py b/yunohost_monitor.py index ed38d3f0..fb4398ad 100644 --- a/yunohost_monitor.py +++ b/yunohost_monitor.py @@ -54,6 +54,40 @@ def uptime(): uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME) print "Uptime: %s" % (str(uptime).split('.')[0]) +def processcount(): + processcount = {'total': 0, 'running': 0, 'sleeping': 0} + process_all = [proc for proc in psutil.process_iter()] + for proc in process_all: + try: + if not proc.is_running(): + try: + process_all.remove(proc) + except Exception: + pass + except psutil.error.NoSuchProcess: + try: + self.process_all.remove(proc) + except Exception: + pass + else: + try: + processcount[str(proc.status)] += 1 + except psutil.error.NoSuchProcess: + pass + except KeyError: + processcount[str(proc.status)] = 1 + finally: + processcount['total'] += 1 + try: + process.append(self.__get_process_stats__(proc)) + except Exception: + pass + + print '%s, %s running, %s sleeping' % (str(processcount['total']), + str(processcount['running']), + str(processcount['sleeping'])) + + def monitor_info(args): if args['memory']: check_memory() @@ -65,3 +99,5 @@ def monitor_info(args): ifconfig() elif args['uptime']: uptime() + elif args['process']: + processcount()