Skip to content

Commit

Permalink
Update lxc_autoscale.py
Browse files Browse the repository at this point in the history
min cores bug fixed 🥳
  • Loading branch information
fabriziosalmi authored Aug 14, 2024
1 parent 2b502aa commit dc1f179
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions usr/local/bin/lxc_autoscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit dc1f179

Please sign in to comment.