Python MIT

proxmox-lxc-autoscale

Automatically scale LXC containers resources on Proxmox hosts

F

fabriziosalmi

Dernière activité 7 sept. 2026
fabriziosalmi/proxmox-lxc-autoscale

260

étoiles

15

forks

15

issues ouvertes

autoscalerautoscalingautoscaling-groupscontainerslxclxc-containersproxmoxproxmox-infrastructureproxmox-toolsscalability

Ce README est souvent en anglais.

LXC AutoScale

Pylint License: MIT Python 3.10+ GitHub release Tests

LXC AutoScale is an async resource management daemon for Proxmox environments. It automatically adjusts CPU and memory allocations for LXC containers based on real-time usage metrics and predefined thresholds. It runs on the Proxmox node or drives one over SSH. Container cloning (horizontal scaling) exists but is experimental and has known defects; see Feature status before enabling it.

  • v2.0 — async architecture, Pydantic config, security hardening
  • Tested on Proxmox VE 8.x (8.3.3) and 9.1, Python 3.10 to 3.14

Quick Start

Method Instructions
Docker Docker
No Docker Install script

Features

  • Async architecture — fully non-blocking event loop using asyncio
  • Pydantic configuration with type validation and ${ENV_VAR} expansion for secrets
  • Automatic vertical scaling of CPU cores and memory based on usage thresholds
  • Horizontal scaling via container cloning (experimental)
  • Per-container or per-group threshold configuration using tiers
  • CPU core pinning to an L3 cache domain (l3:N, a CCD on AMD), a NUMA node (numa:N), or to P-cores and E-cores on hybrid Intel
  • Cgroup-based metrics for both CPU and memory (no pct exec needed)
  • Timezone-aware off-peak scheduling (configurable, defaults to UTC)
  • Host CPU and memory reservation, subtracted from the pool the daemon considers available
  • Container exclusion list (ignore_lxc)
  • Energy efficiency mode that reduces resources during off-peak hours
  • SSH connection pool with configurable host key verification (default: reject)
  • Notifications via email (SMTP), Gotify, and Uptime Kuma (async, fire-and-forget)
  • JSON metrics log with rotation (10MB limit)
  • Local execution or remote execution via SSH
  • Docker support with optional non-root user for API-only mode
  • 445 tests, run in CI on Python 3.10 through 3.14
  • Boost/revert scaling mode — temporary resource boosts with automatic revert after configurable duration

Note

If you need to autoscale Virtual Machine resources on Proxmox hosts, you will like this project.

Quick Start

Prerequisites

  • Proxmox VE 8.x or 9.x (tested on 8.3.3 and 9.1.7)
  • Python 3.10+. The daemon does not start on 3.9: a lock is built at import time and binds an event loop that the runtime then replaces. Proxmox VE 7 ships 3.9 and is no longer supported.
  • Root access to the Proxmox host
  • LXC containers already created and configured
  • Internet connection for downloading the installation script

Installation

curl -sSL https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/install.sh | bash

Tip

Once installed, verify the service is running:

systemctl status lxc_autoscale.service

CPU Measurement

Starting with v1.2.0, CPU usage is measured via host-side cgroup accounting (cgroup v2/v1). This reads the kernel's own CPU time tracking for each container directly from the Proxmox host, without needing to execute commands inside containers. Benefits:

  • Accurate measurements that match what Proxmox shows in its web UI
  • No dependency on LXCFS being installed in containers
  • Minimal overhead (simple file reads instead of pct exec per container)
  • Works correctly on low-core hosts with many containers

If cgroup accounting is unavailable, the daemon falls back to /proc/stat (requires LXCFS) and then to load average estimation.

LXCFS Configuration (optional, for fallback method)

If you want the /proc/stat fallback to work correctly, configure LXCFS with the -l flag in /lib/systemd/system/lxcfs.service:

ExecStart=/usr/bin/lxcfs /var/lib/lxcfs -l

Then run systemctl daemon-reload && systemctl restart lxcfs and restart your containers.

See the Proxmox forum thread for details.

CPU Core Pinning

Pin a tier to a subset of the host's CPUs via the cpu_pinning tier setting. Groups are auto-detected from the kernel, so the config does not hard-code CPU numbers.

# AMD: keep the database on its own CCD, so background work cannot evict its L3.
TIER_databases:
  lxc_containers:
    - "102"
  cpu_pinning: l3:0

TIER_background_tasks:
  lxc_containers:
    - "105"
    - "106"
  cpu_pinning: l3:1

Accepted values: l3:N (one L3 cache domain, a CCD/CCX on AMD), numa:N (one NUMA node), p-cores and e-cores (hybrid Intel only), all, or an explicit range like 0-11 or 0,2,4,6-8. The groups this host offers are logged the first time a tier asks for one, not at startup.

Important

Setting cpu_pinning on a tier disables that tier's CPU scaling. Proxmox derives a container's affinity from cores only when the config carries no explicit cpuset line; the pin writes one, so from the container's next start cores no longer controls anything. Verified on Proxmox VE 9.1. Use one or the other on a given tier, not both.

On a single-socket host with one L3 domain, l3:0 and numa:0 resolve to every CPU, which is no restriction at all. See CPU Core Pinning.

Configuration

LXC AutoScale is configured via a YAML file at /etc/lxc_autoscale/lxc_autoscale.yaml. For detailed configuration options, see the documentation.

Tip

If you need LXC AutoScale configuration for all your LXC containers, you can automatically generate it by running this command:

curl -sSL https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale/lxc_autoscale_autoconf.sh | bash

Additional Resources

Tip

LXC AutoScale ML has been moved to a separate repository.

Frequently Asked Questions

Can I use this on Proxmox 7.x?

LXC AutoScale is tested on Proxmox VE 8.3.3. It may work on older versions, but compatibility is not guaranteed.

Will this work with my existing containers?

Yes. Configure the container IDs in the YAML file and the service will start managing them.

Does this support virtual machines (VMs)?

No, LXC AutoScale is designed for LXC containers only. For VM autoscaling, see proxmox-vm-autoscale.

Can I run this remotely?

Yes. Two options:

Set use_remote_proxmox: true and provide SSH credentials. Every command runs through pct on the far end. There is no REST path, see below.

Can I use the Proxmox REST API instead of SSH?

No. A REST implementation sat in the tree for a year without ever being connected to the daemon, so backend: api changed nothing while appearing to work. It has been removed, and that value is now refused at startup with a message saying why. Building a real one is tracked as #56.

Is it safe to use in production?

Read Feature status first, and test in a non-production environment. Two things to know before you decide. There is no rollback. A --rollback flag existed and restored nothing, because no backup was ever written; it was removed in 2.0.5 rather than left in place looking like a safety net (#88). Container settings live in /etc/pve/lxc/<ctid>.conf and in your Proxmox backups. And the daemon rewrites the configuration of running containers as root, so the blast radius of a mistake is the guest, not the daemon: use ignore_lxc to scope it to containers you are willing to have resized while you evaluate it.

How often does it check container resources?

The default polling interval is 300 seconds (5 minutes). Adjust with the poll_interval setting.

Can I exclude certain containers from autoscaling?

Yes. Add container IDs to the ignore_lxc list in the configuration file.

For more detailed questions and answers, see the Q&A documentation.

Commercial support & consulting

Running this on your Proxmox fleet? I offer paid support, custom development, and consulting - infrastructure automation, hardening, and monitoring & detection. Reach out: fabrizio.salmi@gmail.com.

Contributing

Contributions are welcome. To get involved:

  • Open an issue to report bugs or request features.
  • Submit a pull request.
  • Fork the repository to develop custom features.

Contributors

LXC AutoScale is made better by the people who contribute to it. Thank you to everyone who has helped improve the project.

See the full contributors graph.

Disclaimer

Caution

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

License

LXC AutoScale is licensed under the MIT License, which means you are free to use, modify, and distribute this software with proper attribution. For more details, please see the LICENSE file.

Projets similaires

Automatically scale virtual machines resources on Proxmox hosts

Pythonautoscaleautoscalingproxmox
Ffabriziosalmi
303 étoiles23

ProxLB - An advanced resource scheduler and load balancer for Proxmox clusters.

Pythonautomationcicdload-balancer
Ggyptazy
892 étoiles55

Automatically set GOMAXPROCS to match Linux container CPU quota.

Gocontainercpugo
Uuber-go
4,9 k étoiles175