summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-06-21 11:37:52 -0500
committerGitHub <noreply@github.com>2024-06-21 11:37:52 -0500
commit569b29eafda7073f95784786cf34387df53f2b35 (patch)
tree9bf45a09b006787e4b8f73eff9e610816b3aba21 /src/op_mode
parent9428146485dca8c3cdadce25f321bb7d570c43b8 (diff)
parentd91fa43fd261f0b6de9a6a6a664ad06ab9c05886 (diff)
downloadvyos-1x-569b29eafda7073f95784786cf34387df53f2b35.tar.gz
vyos-1x-569b29eafda7073f95784786cf34387df53f2b35.zip
Merge pull request #3684 from dmbaturin/T6498-uptime-helpers
op mode: T6498: move uptime helpers to vyos.utils.system
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/uptime.py33
1 files changed, 4 insertions, 29 deletions
diff --git a/src/op_mode/uptime.py b/src/op_mode/uptime.py
index 559eed24c..1c1a149ec 100755
--- a/src/op_mode/uptime.py
+++ b/src/op_mode/uptime.py
@@ -18,39 +18,14 @@ import sys
import vyos.opmode
-def _get_uptime_seconds():
- from re import search
- from vyos.utils.file import read_file
-
- data = read_file("/proc/uptime")
- seconds = search("([0-9\.]+)\s", data).group(1)
-
- return int(float(seconds))
-
-def _get_load_averages():
- from re import search
- from vyos.utils.cpu import get_core_count
- from vyos.utils.process import cmd
-
- data = cmd("uptime")
- matches = search(r"load average:\s*(?P<one>[0-9\.]+)\s*,\s*(?P<five>[0-9\.]+)\s*,\s*(?P<fifteen>[0-9\.]+)\s*", data)
-
- core_count = get_core_count()
-
- res = {}
- res[1] = float(matches["one"]) / core_count
- res[5] = float(matches["five"]) / core_count
- res[15] = float(matches["fifteen"]) / core_count
-
- return res
-
def _get_raw_data():
+ from vyos.utils.system import get_uptime_seconds, get_load_averages
from vyos.utils.convert import seconds_to_human
res = {}
- res["uptime_seconds"] = _get_uptime_seconds()
- res["uptime"] = seconds_to_human(_get_uptime_seconds(), separator=' ')
- res["load_average"] = _get_load_averages()
+ uptime_seconds = get_uptime_seconds()
+ res["uptime"] = seconds_to_human(uptime_seconds, separator=' ')
+ res["load_average"] = get_load_averages()
return res