mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
add process count
This commit is contained in:
parent
2caab6a31d
commit
da0f59d254
2 changed files with 41 additions and 0 deletions
|
@ -469,6 +469,11 @@ action_map = {
|
||||||
'full' : '--uptime',
|
'full' : '--uptime',
|
||||||
'help' : _("Show Uptime"),
|
'help' : _("Show Uptime"),
|
||||||
'action' : 'store_true',
|
'action' : 'store_true',
|
||||||
|
},
|
||||||
|
'-p' : {
|
||||||
|
'full' : '--process',
|
||||||
|
'help' : _("Show Process Account"),
|
||||||
|
'action' : 'store_true',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -54,6 +54,40 @@ def uptime():
|
||||||
uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)
|
uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)
|
||||||
print "Uptime: %s" % (str(uptime).split('.')[0])
|
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):
|
def monitor_info(args):
|
||||||
if args['memory']:
|
if args['memory']:
|
||||||
check_memory()
|
check_memory()
|
||||||
|
@ -65,3 +99,5 @@ def monitor_info(args):
|
||||||
ifconfig()
|
ifconfig()
|
||||||
elif args['uptime']:
|
elif args['uptime']:
|
||||||
uptime()
|
uptime()
|
||||||
|
elif args['process']:
|
||||||
|
processcount()
|
||||||
|
|
Loading…
Add table
Reference in a new issue