diff options
author | Daniil Baturin <daniil@vyos.io> | 2022-02-21 08:06:40 -0500 |
---|---|---|
committer | Daniil Baturin <daniil@vyos.io> | 2022-02-21 10:32:07 -0500 |
commit | a3b7e985911eeaccac4fa229563b78c5a64e7e90 (patch) | |
tree | d61bd035889fe8b24c2c4f62316bc54b285821a5 /src/op_mode/show_uptime.py | |
parent | 529af7898d062b42ac33e15bfdc62c14184e098f (diff) | |
download | vyos-1x-a3b7e985911eeaccac4fa229563b78c5a64e7e90.tar.gz vyos-1x-a3b7e985911eeaccac4fa229563b78c5a64e7e90.zip |
T2719: initial batch of standardized structure op mode scripts
Diffstat (limited to 'src/op_mode/show_uptime.py')
-rwxr-xr-x | src/op_mode/show_uptime.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/op_mode/show_uptime.py b/src/op_mode/show_uptime.py index c3dea52e6..1b5e33fa9 100755 --- a/src/op_mode/show_uptime.py +++ b/src/op_mode/show_uptime.py @@ -37,14 +37,27 @@ def get_load_averages(): return res -if __name__ == '__main__': +def get_raw_data(): from vyos.util import seconds_to_human - print("Uptime: {}\n".format(seconds_to_human(get_uptime_seconds()))) + res = {} + res["uptime_seconds"] = get_uptime_seconds() + res["uptime"] = seconds_to_human(get_uptime_seconds()) + res["load_average"] = get_load_averages() + + return res - avgs = get_load_averages() +def get_formatted_output(): + data = get_raw_data() - print("Load averages:") - print("1 minute: {:.02f}%".format(avgs[1]*100)) - print("5 minutes: {:.02f}%".format(avgs[5]*100)) - print("15 minutes: {:.02f}%".format(avgs[15]*100)) + out = "Uptime: {}\n\n".format(data["uptime"]) + avgs = data["load_average"] + out += "Load averages:\n" + out += "1 minute: {:.02f}%\n".format(avgs[1]*100) + out += "5 minutes: {:.02f}%\n".format(avgs[5]*100) + out += "15 minutes: {:.02f}%\n".format(avgs[15]*100) + + return out + +if __name__ == '__main__': + print(get_formatted_output()) |