mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Split monitor unit argument into separate arguments
This commit is contained in:
parent
ae1689e471
commit
0f2f59daf3
3 changed files with 72 additions and 44 deletions
|
@ -57,9 +57,9 @@ Specifications
|
|||
|
||||
### Monitoring
|
||||
|
||||
yunohost monitor disk [-u {io,filesystem}] [-m]
|
||||
yunohost monitor network [-u {usage,infos}]
|
||||
yunohost monitor system [-u {memory,cpu,process,uptime,infos}]
|
||||
yunohost monitor disk [-h] [-m MOUNTPOINT] [-t] [-f]
|
||||
yunohost monitor network [-h] [-u] [-i]
|
||||
yunohost monitor system [-h] [-m] [-u] [-i] [-p] [-c]
|
||||
yunohost monitor process [-h] [-e PROCESS] [-d PROCESS]
|
||||
[--stop PROCESS] [-c PORT] [-i]
|
||||
[--start PROCESS]
|
||||
|
|
|
@ -428,40 +428,74 @@ monitor:
|
|||
disk:
|
||||
action_help: Monitor disk space and usage
|
||||
arguments:
|
||||
-u:
|
||||
full: --unit
|
||||
help: Unit to monitor
|
||||
choices:
|
||||
- io
|
||||
- filesystem
|
||||
-f:
|
||||
full: --filesystem
|
||||
help: Show filesystem disk space
|
||||
action: append_const
|
||||
const: filesystem
|
||||
dest: units
|
||||
-t:
|
||||
full: --io
|
||||
help: Show I/O throughput
|
||||
action: append_const
|
||||
const: io
|
||||
dest: units
|
||||
-m:
|
||||
full: --mountpoint
|
||||
help: Device mountpoint
|
||||
help: Monitor only the device mounted on MOUNTPOINT
|
||||
action: store
|
||||
|
||||
### monitor_network()
|
||||
network:
|
||||
action_help: Monitor network interfaces
|
||||
arguments:
|
||||
-u:
|
||||
full: --unit
|
||||
help: Unit to monitor
|
||||
choices:
|
||||
- usage
|
||||
- infos
|
||||
full: --usage
|
||||
help: Show interfaces bit rates
|
||||
action: append_const
|
||||
const: usage
|
||||
dest: units
|
||||
-i:
|
||||
full: --infos
|
||||
help: Show network informations
|
||||
action: append_const
|
||||
const: infos
|
||||
dest: units
|
||||
|
||||
### monitor_system()
|
||||
system:
|
||||
action_help: Monitor system informations and usage
|
||||
arguments:
|
||||
-m:
|
||||
full: --memory
|
||||
help: Show memory usage
|
||||
action: append_const
|
||||
const: memory
|
||||
dest: units
|
||||
-c:
|
||||
full: --cpu
|
||||
help: Show CPU usage and load
|
||||
action: append_const
|
||||
const: cpu
|
||||
dest: units
|
||||
-p:
|
||||
full: --process
|
||||
help: Show processes summary
|
||||
action: append_const
|
||||
const: process
|
||||
dest: units
|
||||
-u:
|
||||
full: --unit
|
||||
help: Unit to monitor
|
||||
choices:
|
||||
- memory
|
||||
- cpu
|
||||
- process
|
||||
- uptime
|
||||
- infos
|
||||
full: --uptime
|
||||
help: Show the system uptime
|
||||
action: append_const
|
||||
const: uptime
|
||||
dest: units
|
||||
-i:
|
||||
full: --infos
|
||||
help: Show system informations
|
||||
action: append_const
|
||||
const: infos
|
||||
dest: units
|
||||
|
||||
process:
|
||||
action_help: Check Process
|
||||
|
|
|
@ -96,12 +96,12 @@ def process_check(args):
|
|||
return { 'Status' : result }
|
||||
|
||||
|
||||
def monitor_disk(unit=None, mountpoint=None):
|
||||
def monitor_disk(units=None, mountpoint=None):
|
||||
"""
|
||||
Monitor disk space and usage
|
||||
|
||||
Keyword argument:
|
||||
unit -- Unit to monitor
|
||||
units -- Unit(s) to monitor
|
||||
mountpoint -- Device mountpoint
|
||||
|
||||
"""
|
||||
|
@ -109,10 +109,8 @@ def monitor_disk(unit=None, mountpoint=None):
|
|||
result_dname = None
|
||||
result = {}
|
||||
|
||||
if unit is None:
|
||||
if units is None:
|
||||
units = ['io', 'filesystem']
|
||||
else:
|
||||
units = [unit]
|
||||
|
||||
# Get mounted block devices
|
||||
devices = {}
|
||||
|
@ -122,7 +120,7 @@ def monitor_disk(unit=None, mountpoint=None):
|
|||
if m and (mountpoint is None or m.group(2) == mountpoint):
|
||||
(dn, dm) = (m.group(1), m.group(2))
|
||||
devices[dn] = dm
|
||||
result[dn] = {} if unit is None else []
|
||||
result[dn] = {} if len(units) > 1 else []
|
||||
result_dname = dn if mountpoint is not None else None
|
||||
if len(devices) == 0:
|
||||
raise YunoHostError(1, _("Unknown mountpoint '%s'") % mountpoint)
|
||||
|
@ -134,7 +132,7 @@ def monitor_disk(unit=None, mountpoint=None):
|
|||
dname = d['disk_name']
|
||||
if dname in devices.keys():
|
||||
del d['disk_name']
|
||||
if unit is None:
|
||||
if len(units) > 1:
|
||||
result[dname][u] = d
|
||||
else:
|
||||
d['mnt_point'] = devices[dname]
|
||||
|
@ -147,7 +145,7 @@ def monitor_disk(unit=None, mountpoint=None):
|
|||
if dm != dmount:
|
||||
continue
|
||||
del d['device_name']
|
||||
if unit is None:
|
||||
if len(units) > 1:
|
||||
result[dn][u] = d
|
||||
else:
|
||||
result[dn] = d
|
||||
|
@ -159,21 +157,19 @@ def monitor_disk(unit=None, mountpoint=None):
|
|||
return result
|
||||
|
||||
|
||||
def monitor_network(unit=None):
|
||||
def monitor_network(units=None):
|
||||
"""
|
||||
Monitor network interfaces
|
||||
|
||||
Keyword argument:
|
||||
unit -- Unit to monitor
|
||||
units -- Unit(s) to monitor
|
||||
|
||||
"""
|
||||
glances = _get_glances_api()
|
||||
result = {}
|
||||
|
||||
if unit is None:
|
||||
if units is None:
|
||||
units = ['usage', 'infos']
|
||||
else:
|
||||
units = [unit]
|
||||
|
||||
# Get network devices and their addresses
|
||||
devices = {}
|
||||
|
@ -219,25 +215,23 @@ def monitor_network(unit=None):
|
|||
raise YunoHostError(1, _("Unknown unit '%s'") % u)
|
||||
|
||||
if len(units) == 1:
|
||||
return result[unit]
|
||||
return result[units[0]]
|
||||
return result
|
||||
|
||||
|
||||
def monitor_system(unit=None):
|
||||
def monitor_system(units=None):
|
||||
"""
|
||||
Monitor system informations and usage
|
||||
|
||||
Keyword argument:
|
||||
unit -- Unit to monitor
|
||||
units -- Unit(s) to monitor
|
||||
|
||||
"""
|
||||
glances = _get_glances_api()
|
||||
result = {}
|
||||
|
||||
if unit is None:
|
||||
if units is None:
|
||||
units = ['memory', 'cpu', 'process', 'uptime', 'infos']
|
||||
else:
|
||||
units = [unit]
|
||||
|
||||
# Retrieve monitoring for unit(s)
|
||||
for u in units:
|
||||
|
@ -260,8 +254,8 @@ def monitor_system(unit=None):
|
|||
else:
|
||||
raise YunoHostError(1, _("Unknown unit '%s'") % u)
|
||||
|
||||
if len(units) == 1 and type(result[unit]) is not str:
|
||||
return result[unit]
|
||||
if len(units) == 1 and type(result[units[0]]) is not str:
|
||||
return result[units[0]]
|
||||
return result
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue