summaryrefslogtreecommitdiff
path: root/src/op_mode/memory.py
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2022-11-02 14:55:27 +0200
committerViacheslav Hletenko <v.gletenko@vyos.io>2022-11-02 12:59:57 +0000
commit46eda54c88ae96ed1f4aaa9ce56c505ed837f3d7 (patch)
tree852b802c592919fec3fe66c14dd2f4aaaf8fd7ed /src/op_mode/memory.py
parent738641a6c66d22c09b8c028ee3d8a90527d9701f (diff)
parentf2ec92a78c4ee2a35e7d071387460fc6ce360740 (diff)
downloadvyos-1x-46eda54c88ae96ed1f4aaa9ce56c505ed837f3d7.tar.gz
vyos-1x-46eda54c88ae96ed1f4aaa9ce56c505ed837f3d7.zip
T4758: Fix conflicts op-mode-standardized
Diffstat (limited to 'src/op_mode/memory.py')
-rwxr-xr-xsrc/op_mode/memory.py27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/op_mode/memory.py b/src/op_mode/memory.py
index 178544be4..7666de646 100755
--- a/src/op_mode/memory.py
+++ b/src/op_mode/memory.py
@@ -20,7 +20,7 @@ import sys
import vyos.opmode
-def _get_system_memory():
+def _get_raw_data():
from re import search as re_search
def find_value(keyword, mem_data):
@@ -38,7 +38,7 @@ def _get_system_memory():
used = total - available
- res = {
+ mem_data = {
"total": total,
"free": available,
"used": used,
@@ -46,24 +46,21 @@ def _get_system_memory():
"cached": cached
}
- return res
-
-def _get_system_memory_human():
- from vyos.util import bytes_to_human
-
- mem = _get_system_memory()
-
- for key in mem:
+ for key in mem_data:
# The Linux kernel exposes memory values in kilobytes,
# so we need to normalize them
- mem[key] = bytes_to_human(mem[key], initial_exponent=10)
+ mem_data[key] = mem_data[key] * 1024
- return mem
-
-def _get_raw_data():
- return _get_system_memory_human()
+ return mem_data
def _get_formatted_output(mem):
+ from vyos.util import bytes_to_human
+
+ # For human-readable outputs, we convert bytes to more convenient units
+ # (100M, 1.3G...)
+ for key in mem:
+ mem[key] = bytes_to_human(mem[key])
+
out = "Total: {}\n".format(mem["total"])
out += "Free: {}\n".format(mem["free"])
out += "Used: {}".format(mem["used"])