Skip to content

Commit

Permalink
Update lxc_utils.py
Browse files Browse the repository at this point in the history
should fix [this issue](#16)
  • Loading branch information
fabriziosalmi authored Dec 1, 2024
1 parent cb283de commit 5cabc90
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lxc_autoscale/lxc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,17 @@ def get_total_memory():
Returns:
int: The amount of available memory in MB.
"""
total_memory = int(run_command("free -m | awk '/Mem:/ {print $2}'"))
try:
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
else:
total_memory = int(command_output.strip())
except (ValueError, subprocess.CalledProcessError) as e:
logging.error(f"Failed to retrieve total memory: {e}")
total_memory = 0

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, "
Expand Down

0 comments on commit 5cabc90

Please sign in to comment.