From 9afe078da3d63b99b6b6d7a719304238212c2113 Mon Sep 17 00:00:00 2001 From: fab Date: Fri, 6 Dec 2024 08:54:41 +0100 Subject: [PATCH] Update lxc_utils.py Fix [this issue](https://github.com/fabriziosalmi/proxmox-lxc-autoscale/issues/17) --- lxc_autoscale/lxc_utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lxc_autoscale/lxc_utils.py b/lxc_autoscale/lxc_utils.py index 2da81be..62bd3a6 100644 --- a/lxc_autoscale/lxc_utils.py +++ b/lxc_autoscale/lxc_utils.py @@ -194,7 +194,8 @@ def get_total_memory(): int: The amount of available memory in MB. """ try: - command_output = run_command("free -m | awk '/^MemTotal:/ {print $2}')") + # Fixed command by removing extra parenthesis + command_output = run_command("free -m | awk '/^MemTotal:/ {print $2}'") if not command_output: logging.warning("Failed to retrieve total memory. Defaulting to 0MB.") total_memory = 0 @@ -211,6 +212,13 @@ def get_total_memory(): ) return available_memory + available_memory = max(0, total_memory - DEFAULTS['reserve_memory_mb']) + logging.debug( + f"Total memory: {total_memory}MB, Reserved memory: {DEFAULTS['reserve_memory_mb']}MB, " + f"Available memory: {available_memory}MB" + ) + return available_memory + import time import logging