mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
merging
This commit is contained in:
commit
0367811b6e
3 changed files with 76 additions and 29 deletions
|
@ -384,9 +384,25 @@ monitor:
|
|||
full: --uptime
|
||||
help: Show Uptime
|
||||
action: store_true
|
||||
-p:
|
||||
full: --process
|
||||
help: Show Process Account
|
||||
process:
|
||||
action_help: Check Process
|
||||
arguments:
|
||||
-e:
|
||||
full: --enable
|
||||
help: Enable process
|
||||
-d:
|
||||
full: --disable
|
||||
help: Disable process
|
||||
--start:
|
||||
help: Start process
|
||||
--stop:
|
||||
help: Stop process
|
||||
-c:
|
||||
full: --check
|
||||
help: Check process
|
||||
-i:
|
||||
full: --info
|
||||
help: Process info
|
||||
action: store_true
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,12 @@ import os
|
|||
import sys
|
||||
import argparse
|
||||
import gettext
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
sys.stderr.write('Error: Yunohost CLI Require yaml lib\n')
|
||||
sys.stderr.write('apt-get install python-yaml\n')
|
||||
sys.exit(1)
|
||||
import yaml
|
||||
import json
|
||||
if not __debug__:
|
||||
|
|
|
@ -10,7 +10,7 @@ except ImportError:
|
|||
sys.stderr.write('apt-get install python-psutil\n')
|
||||
sys.exit(1)
|
||||
from datetime import datetime, timedelta
|
||||
#from psutil._compat import print_
|
||||
from yunohost import YunoHostError, win_msg, colorize, validate, get_required_args
|
||||
|
||||
def bytes2human(n):
|
||||
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
||||
|
@ -27,16 +27,16 @@ def check_disk():
|
|||
templ = "%s,%s/%s,%s,%s"
|
||||
for part in psutil.disk_partitions(all=False):
|
||||
usage = psutil.disk_usage(part.mountpoint)
|
||||
print(templ % (part.mountpoint,
|
||||
result = (templ % (part.mountpoint,
|
||||
bytes2human(usage.used),
|
||||
bytes2human(usage.total),
|
||||
bytes2human(usage.free),
|
||||
int(usage.percent)))
|
||||
print result
|
||||
|
||||
def check_cpu():
|
||||
print psutil.cpu_percent(interval=1)
|
||||
|
||||
|
||||
def check_memory():
|
||||
print getattr(psutil.phymem_usage(), "percent")
|
||||
print getattr(psutil.virtmem_usage(), "percent")
|
||||
|
@ -51,9 +51,8 @@ def ifconfig():
|
|||
print 'MAC NOT FOUND!'
|
||||
|
||||
def uptime():
|
||||
uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)
|
||||
print "Uptime: %s" % (str(uptime).split('.')[0])
|
||||
|
||||
uptimeres = (str(datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)).split('.')[0])
|
||||
return uptimeres
|
||||
def processcount():
|
||||
processcount = {'total': 0, 'running': 0, 'sleeping': 0}
|
||||
process_all = [proc for proc in psutil.process_iter()]
|
||||
|
@ -83,9 +82,21 @@ def processcount():
|
|||
except Exception:
|
||||
pass
|
||||
|
||||
print '%s, %s running, %s sleeping' % (str(processcount['total']),
|
||||
str(processcount['running']),
|
||||
str(processcount['sleeping']))
|
||||
def process_enable(args):
|
||||
print 'process_enable'
|
||||
|
||||
def process_disable(args):
|
||||
uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)
|
||||
print "Uptime: %s" % (str(uptime).split('.')[0])
|
||||
|
||||
def process_start(args):
|
||||
print 'process_start'
|
||||
|
||||
def process_stop(args):
|
||||
print 'process_stop'
|
||||
|
||||
def process_check(args):
|
||||
print 'process_check'
|
||||
|
||||
|
||||
def monitor_info(args):
|
||||
|
@ -99,5 +110,19 @@ def monitor_info(args):
|
|||
ifconfig()
|
||||
elif args['uptime']:
|
||||
uptime()
|
||||
elif args['process']:
|
||||
return { 'Uptime' : uptimeres }
|
||||
|
||||
def monitor_process(args):
|
||||
if args['enable']:
|
||||
process_enable()
|
||||
elif args['disable']:
|
||||
process_disable()
|
||||
elif args['start']:
|
||||
process_start()
|
||||
elif args['stop']:
|
||||
process_stop()
|
||||
elif args['check']:
|
||||
process_check()
|
||||
elif args['info']:
|
||||
processcount()
|
||||
return { _("Total") : str(processcount['total']), _("Running") : str(processcount['running']), _("Sleeping") : str(processcount['sleeping']) }
|
||||
|
|
Loading…
Reference in a new issue