Skip to content

Commit

Permalink
Update lxc_utils.py
Browse files Browse the repository at this point in the history
Fix [this issue](#17)
  • Loading branch information
fabriziosalmi authored Dec 6, 2024
1 parent 5cabc90 commit 9afe078
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lxc_autoscale/lxc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9afe078

Please sign in to comment.