From dc1f179e3e9bad494c95352d254dff8b91a72048 Mon Sep 17 00:00:00 2001 From: fab Date: Wed, 14 Aug 2024 23:47:07 +0200 Subject: [PATCH] Update lxc_autoscale.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit min cores bug fixed 🥳 --- usr/local/bin/lxc_autoscale.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/usr/local/bin/lxc_autoscale.py b/usr/local/bin/lxc_autoscale.py index 1aa3d32..511a54c 100644 --- a/usr/local/bin/lxc_autoscale.py +++ b/usr/local/bin/lxc_autoscale.py @@ -26,7 +26,7 @@ 'core_min_increment': 1, 'core_max_increment': 8, 'memory_min_increment': 512, - 'min_cores': 1, + 'min_cores': 2, # Changed default min_cores to 2 as per the requirement 'max_cores': 12, 'min_memory': 512, 'min_decrease_chunk': 512, @@ -507,12 +507,14 @@ def adjust_resources(containers): if new_cores >= min_cores: logging.info(f"Decreasing cores for container {ctid} by {decrement}...") run_command(f"pct set {ctid} -cores {new_cores}") - available_cores += decrement + available_cores += (current_cores - new_cores) # Corrected available core logic cores_changed = True send_gotify_notification( f"CPU Decreased for Container {ctid}", f"CPU cores decreased to {new_cores}." ) + else: + logging.warning(f"Cannot decrease cores below min_cores for container {ctid}") # Adjust memory if needed if mem_usage > mem_upper: @@ -593,7 +595,6 @@ def main_loop(): logging.error(f"Error in main loop: {e}") break - # Main execution flow if __name__ == "__main__": with acquire_lock() as lock_file: