From 0f2f59daf3ab4aabc22ec3ca7eb48424157e8fad Mon Sep 17 00:00:00 2001 From: Jerome Lebleu Date: Tue, 3 Dec 2013 00:41:32 +0100 Subject: [PATCH] Split monitor unit argument into separate arguments --- README.md | 6 ++-- action_map.yml | 74 +++++++++++++++++++++++++++++++++------------ yunohost_monitor.py | 36 +++++++++------------- 3 files changed, 72 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 0ff3c6c3..1efdf0ea 100644 --- a/README.md +++ b/README.md @@ -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] diff --git a/action_map.yml b/action_map.yml index 784e1367..13984d7d 100644 --- a/action_map.yml +++ b/action_map.yml @@ -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 diff --git a/yunohost_monitor.py b/yunohost_monitor.py index e3a31133..f62738b1 100644 --- a/yunohost_monitor.py +++ b/yunohost_monitor.py @@ -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