mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Add monitor
This commit is contained in:
parent
c3253b24ac
commit
4add88a5a0
2 changed files with 89 additions and 5 deletions
38
parse_args
38
parse_args
|
@ -411,8 +411,35 @@ action_dict = {
|
|||
},
|
||||
'monitor' : {
|
||||
'category_help' : _("Monitoring functions"),
|
||||
'actions' : {}
|
||||
},
|
||||
'actions' : {
|
||||
'info': {
|
||||
'action_help' : _("Check System"),
|
||||
'connections' : ['ldap'],
|
||||
'arguments' : {
|
||||
'-m' : {
|
||||
'full' : '--memory',
|
||||
'help' : _("Check Memory"),
|
||||
'action' : 'store_true',
|
||||
},
|
||||
'-c' : {
|
||||
'full' : '--cpu',
|
||||
'help' : _("Check CPU"),
|
||||
'action' : 'store_true',
|
||||
},
|
||||
'-d' : {
|
||||
'full' : '--disk',
|
||||
'help' : _("Check Disk"),
|
||||
'action' : 'store_true',
|
||||
},
|
||||
'-i' : {
|
||||
'full' : '--ifconfig',
|
||||
'help' : _("Ifconfig"),
|
||||
'action' : 'store_true',
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
'tools' : {
|
||||
'category_help' : _("Specific tools"),
|
||||
'actions' : {}
|
||||
|
@ -459,9 +486,10 @@ def parse_dict(action_dict):
|
|||
if 'actions' in category_params:
|
||||
for action, action_params in category_params['actions'].items():
|
||||
# Connections settings
|
||||
for connection in connections_available:
|
||||
if connection in action_params['connections']:
|
||||
connections_enabled.append(connection)
|
||||
if 'connections' in action_params:
|
||||
for connection in connections_available:
|
||||
if connection in action_params['connections']:
|
||||
connections_enabled.append(connection)
|
||||
if 'action_help' not in action_params: action_params['action_help'] = ''
|
||||
parsers[category + '_' + action] = subparsers_action[category].add_parser(action, help=action_params['action_help'])
|
||||
# Set the action s related function
|
||||
|
|
56
yunohost_monitor.py
Normal file
56
yunohost_monitor.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import psutil
|
||||
from psutil._compat import print_
|
||||
|
||||
def bytes2human(n):
|
||||
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
||||
prefix = {}
|
||||
for i, s in enumerate(symbols):
|
||||
prefix[s] = 1 << (i+1)*10
|
||||
for s in reversed(symbols):
|
||||
if n >= prefix[s]:
|
||||
value = float(n) / prefix[s]
|
||||
return '%.1f%s' % (value, s)
|
||||
return "%sB" % n
|
||||
|
||||
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,
|
||||
bytes2human(usage.used),
|
||||
bytes2human(usage.total),
|
||||
bytes2human(usage.free),
|
||||
int(usage.percent)))
|
||||
|
||||
def check_cpu():
|
||||
print psutil.cpu_percent(interval=1)
|
||||
|
||||
|
||||
def check_memory():
|
||||
print getattr(psutil.phymem_usage(), "percent")
|
||||
print getattr(psutil.virtmem_usage(), "percent")
|
||||
|
||||
def ifconfig():
|
||||
output = subprocess.Popen(['ifconfig'], stdout=subprocess.PIPE).communicate()[0]
|
||||
if 'HWaddr' in output:
|
||||
mac = output[(output.find('HWaddr')+7):(output.find('HWaddr')+24)]
|
||||
ip = output[(output.find('Bcast')-15):(output.find('inet')+22)]
|
||||
print 'MAC: ' + mac + ' IP: ' +ip
|
||||
else:
|
||||
return 'MAC NOT FOUND!'
|
||||
|
||||
|
||||
def monitor_info(args, connections):
|
||||
if args['memory'] == True:
|
||||
check_memory()
|
||||
elif args['cpu'] == True:
|
||||
check_cpu()
|
||||
elif args['disk'] == True:
|
||||
check_disk()
|
||||
elif args['ifconfig'] == True:
|
||||
ifconfig()
|
Loading…
Add table
Reference in a new issue