fabriziosalmi / proxmox-vm-autoscale

Automatically scale virtual machines resources on Proxmox hosts
MIT License
104 stars 2 forks source link
autoscale autoscaling proxmox proxmox-infrastructure resource-manager scaling threshold virtual-machine

πŸš€ VM Autoscale

🌟 Overview

Proxmox VM Autoscale is a dynamic scaling service that automatically adjusts virtual machine (VM) resources (CPU cores and RAM) on your Proxmox Virtual Environment (VE) based on real-time metrics and user-defined thresholds. This solution helps ensure efficient resource usage, optimizing performance and resource availability dynamically.

The service supports multiple Proxmox hosts via SSH connections and can be easily installed and managed as a systemd service for seamless automation.

[!IMPORTANT] To enable scaling of VM resources, make sure NUMA and hotplug features are enabled:

  • Enable NUMA: VM > Hardware > Processors > Enable NUMA β˜‘οΈ
  • Enable CPU Hotplug: VM > Options > Hotplug > CPU β˜‘οΈ
  • Enable Memory Hotplug: VM > Options > Hotplug > Memory β˜‘οΈ

✨ Features

πŸ“‹ Prerequisites

[!NOTE] To autoscale LXC containers on Proxmox hosts, you may be interested in this related project.

πŸš€ Quick Start

To install Proxmox VM Autoscale, execute the following curl bash command. This command will automatically clone the repository, execute the installation script, and set up the service for you:

bash <(curl -s https://raw.githubusercontent.com/fabriziosalmi/proxmox-vm-autoscale/main/install.sh)

🎯 This installation script will:

[!NOTE] The service is enabled but not started automatically at the end of the installation. To start it manually, use the following command.

[!IMPORTANT] Make sure to review the official Proxmox documentation for the hotplug feature requirements to enable scaling virtual machines on the fly.

⚑ Usage

▢️ Start/Stop the Service

To start the autoscaling service:

sudo systemctl start vm_autoscale.service

To stop the service:

sudo systemctl stop vm_autoscale.service

πŸ” Check the Status

To view the service status:

sudo systemctl status vm_autoscale.service

πŸ“œ Logs

Logs are saved to /var/log/vm_autoscale.log. You can monitor the logs in real-time using:

tail -f /var/log/vm_autoscale.log

Or by using journalctl:

journalctl -u vm_autoscale.service -f

βš™οΈ Configuration

The configuration file (config.yaml) is located at /usr/local/bin/vm_autoscale/config.yaml. This file contains settings for scaling thresholds, resource limits, Proxmox hosts, and VM information.

Example Configuration

scaling_thresholds:
  cpu:
    high: 80
    low: 20
  ram:
    high: 85
    low: 25

scaling_limits:
  min_cores: 1
  max_cores: 8
  min_ram_mb: 512
  max_ram_mb: 16384

check_interval: 60  # Check every 60 seconds

proxmox_hosts:
  - name: host1
    host: 192.168.1.10
    ssh_user: root
    ssh_password: your_password_here
    ssh_key: /path/to/ssh_key

virtual_machines:
  - vm_id: 101
    proxmox_host: host1
    scaling_enabled: true
    cpu_scaling: true
    ram_scaling: true

logging:
  level: INFO
  log_file: /var/log/vm_autoscale.log

gotify:
  enabled: true
  server_url: https://gotify.example.com
  app_token: your_gotify_app_token_here
  priority: 5

βš™οΈ Configuration Details

πŸ“² Gotify Notifications

Gotify is used to send real-time notifications regarding scaling actions. Configure Gotify in the config.yaml file:

πŸ‘¨β€πŸ’» Development

πŸ”§ Requirements

πŸ› Running Manually

To run the script manually for debugging or testing:

python3 /usr/local/bin/vm_autoscale/autoscale.py

🀝 Contributing

Contributions are more than welcome! If you encounter a bug or have suggestions for improvement, please submit an issue or a pull request.

⚠️ Disclaimer

[!CAUTION] The author assumes no responsibility for any damage or issues that may arise from using this tool.

πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for complete details.