summaryrefslogtreecommitdiff
path: root/src/op_mode/show_uptime.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-02-21 14:03:22 -0600
committerGitHub <noreply@github.com>2022-02-21 14:03:22 -0600
commitd59fac9148ccbe677716baebac813c45b84de712 (patch)
tree5fd228cf341163e689692d26effa0885090d86fb /src/op_mode/show_uptime.py
parent36a8c636d6d91550237bfa19b12de949319bc692 (diff)
parenta3b7e985911eeaccac4fa229563b78c5a64e7e90 (diff)
downloadvyos-1x-d59fac9148ccbe677716baebac813c45b84de712.tar.gz
vyos-1x-d59fac9148ccbe677716baebac813c45b84de712.zip
Merge pull request #1233 from dmbaturin/structured-op-mode
T2719: initial batch of standardized structure op mode scripts
Diffstat (limited to 'src/op_mode/show_uptime.py')
-rwxr-xr-xsrc/op_mode/show_uptime.py27
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())