diff options
author | Daniil Baturin <daniil@baturin.org> | 2024-06-19 18:24:06 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2024-06-21 17:30:43 +0100 |
commit | d91fa43fd261f0b6de9a6a6a664ad06ab9c05886 (patch) | |
tree | 2a713b8193a1f44fc0c9d373a736e4f7426a458c /python | |
parent | 47634378a00c41cab611092f200e86f9124f7ca8 (diff) | |
download | vyos-1x-d91fa43fd261f0b6de9a6a6a664ad06ab9c05886.tar.gz vyos-1x-d91fa43fd261f0b6de9a6a6a664ad06ab9c05886.zip |
op mode: T6498: move uptime helpers to vyos.utils.system
to be able to call them from the new tech-support script
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/utils/system.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/python/vyos/utils/system.py b/python/vyos/utils/system.py index 55813a5f7..f427032a4 100644 --- a/python/vyos/utils/system.py +++ b/python/vyos/utils/system.py @@ -1,4 +1,4 @@ -# Copyright 2023 VyOS maintainers and contributors <maintainers@vyos.io> +# Copyright 2023-2024 VyOS maintainers and contributors <maintainers@vyos.io> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -98,3 +98,33 @@ def load_as_module(name: str, path: str): mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod + +def get_uptime_seconds(): + """ Returns system uptime in seconds """ + from re import search + from vyos.utils.file import read_file + + data = read_file("/proc/uptime") + seconds = search(r"([0-9\.]+)\s", data).group(1) + res = int(float(seconds)) + + return res + +def get_load_averages(): + """ Returns load averages for 1, 5, and 15 minutes as a dict """ + from re import search + from vyos.utils.file import read_file + from vyos.utils.cpu import get_core_count + + data = read_file("/proc/loadavg") + matches = search(r"\s*(?P<one>[0-9\.]+)\s+(?P<five>[0-9\.]+)\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 + |