Skip to content

Commit

Permalink
Merge pull request #1 from gyptazy/release/0.9.0
Browse files Browse the repository at this point in the history
release(0.9.9): Create initial test release
  • Loading branch information
gyptazy authored Jul 7, 2024
2 parents b1f8dcd + e3d0005 commit ca18334
Show file tree
Hide file tree
Showing 20 changed files with 882 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changelogs/0.9.0/1_initial_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
added:
- Development release of Proxmox Rebalancing Service
1 change: 1 addition & 0 deletions .changelogs/0.9.0/release_meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
date: 2024-02-01
2 changes: 2 additions & 0 deletions .changelogs/0.9.9/1_initial_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
added:
- Initial public development release of Proxmox Rebalancing Service
1 change: 1 addition & 0 deletions .changelogs/0.9.9/release_meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
date: 2024-07-06
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev/
171 changes: 169 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,169 @@
# proxmox-rebalancing-service
Rebalancing VM workloads across nodes within a Proxmox cluster.
# Proxmox Rebalancing Service
<img align="left" src="https://cdn.gyptazy.ch/images/proxmox-rebalancing-service-gyptazy-text.jpg"/>
<br>

<p float="center"><img src="https://img.shields.io/github/license/gyptazy/proxmox-rebalancing-service"/><img src="https://img.shields.io/github/contributors/gyptazy/proxmox-rebalancing-service"/><img src="https://img.shields.io/github/last-commit/gyptazy/proxmox-rebalancing-service/main"/><img src="https://img.shields.io/github/issues-raw/gyptazy/proxmox-rebalancing-service"/><img src="https://img.shields.io/github/issues-pr/gyptazy/proxmox-rebalancing-service"/></p>


## Table of Content
* Introduction
* Video of Migration
* Features
* Usage
* Dependencies
* Options
* Parameters
* Systemd
* Manuel
* Proxmox GUI Integration
* Quick Start
* Motivation
* References
* Packages
* Misc
* Bugs
* Contributing
* Author(s)

## Introduction
The `Proxmox Rebalancing Service` (PRS) is an advanced tool designed to enhance the efficiency and performance of Proxmox clusters by optimizing the distribution of virtual machines (VMs) across the cluster nodes by using the Proxmox API. PRS meticulously gathers and analyzes a comprehensive set of resource metrics from both the cluster nodes and the running VMs. These metrics include CPU usage, memory consumption, and disk utilization, specifically focusing on local disk resources.

PRS collects resource usage data from each node in the Proxmox cluster, including CPU, (local) disk and memory utilization. Additionally, it gathers resource usage statistics from all running VMs, ensuring a granular understanding of the cluster's workload distribution.

Intelligent rebalancing is a key feature of PRS where it re-balances VMs based on their memory, disk or cpu usage, ensuring that no node is overburdened while others remain underutilized. The rebalancing capabilities of PRS significantly enhance cluster performance and reliability. By ensuring that resources are evenly distributed, PRS helps prevent any single node from becoming a performance bottleneck, improving the reliability and stability of the cluster. Efficient rebalancing leads to better utilization of available resources, potentially reducing the need for additional hardware investments and lowering operational costs.

Automated rebalancing reduces the need for manual actions, allowing operators to focus on other critical tasks, thereby increasing operational efficiency.

### Video of Migration
<img src="https://cdn.gyptazy.ch/images/proxmox-rebalancing-service-gyptazy-video.gif"/>

## Features
* Rebalance the cluster by:
* Memory
* Disk (only local storage)
* CPU
* Performing
* Periodically
* One-shot solution
* Filter
* Exclude nodes
* Exclude virtual machines
* Migrate VM workloads away (e.g. maintenance preparation)
* Usage
* One-Shot (one-shot)
* Periodically (daemon)
* Proxmox Web GUI Integration (optional)

## Usage
Running PRS is easy and it runs almost everywhere since it just depends on Python3 and the proxmoxer library. Therefore, it can directly run on a Proxmox node, dedicated systems like Debian, RedHat, or even FreeBSD, as long as the API is reachable by the client running PRS.

### Dependencies
* Python3
* proxmoxer (Python module)

### Options
The following options can be set in the `prs.conf` file:

| Option | Example | Description |
|------|:------:|:------:|
| api_host | hypervisor01.gyptazy.ch | Host or IP address of the remote Proxmox API. |
| api_user | root@pam | Username for the API. |
| api_pass | FooBar | Password for the API. |
| verify_ssl | 1 | Validate SSL certificates (1) or ignore (0). (default: 1) |
| method | memory | Defines the balancing method (default: memory) where you can use `memory`, `disk` or `cpu`. |
| ignore_nodes | dummynode01,dummynode02 | Defines a comma separated list of nodes to exclude. |
| ignore_vms | testvm01,testvm02 | Defines a comma separated list of VMs to exclude. |
| daemon | 1 | Run as a daemon (1) or one-shot (0). (default: 1) |
| schedule | 24 | Hours to rebalance in hours. (default: 24) |

An example of the configuration file looks like:
```
[proxmox]
api_host: hypervisor01.gyptazy.ch
api_user: root@pam
api_pass: FooBar
verify_ssl: 1
[balancing]
method: memory
ignore_nodes: dummynode01,dummynode02
ignore_vms: testvm01,testvm02
[service]
daemon: 1
```

### Parameters
The following options and parameters are currently supported:

| Option | Long Option | Description | Default |
|------|:------:|------:|------:|
| -c | --config | Path to a config file. | /etc/proxmox-rebalancing-service/prs.conf (default) |

### Systemd
When installing a Linux distribution (such as .deb or .rpm) file, this will be shipped with a systemd unit file. The default configuration file will be sourced from `/etc/proxmox-rebalancing-service/prs.conf`.

| Unit Name | Options |
|------|:------:|
| proxmox-rebalancing-service | start, stop, status, restart |

### Manual
A manual installation is possible and also supports BSD based systems. Proxmox Rebalancing Service relies on mainly two important files:
* proxmox-rebalancing-service (Python Executable)
* prs.conf (Config file)

The executable must be able to read the config file, if no dedicated config file is given by the `-c` argument, PRS tries to read it from `/etc/proxmox-rebalancing-service/prs.conf`.

### Proxmox GUI Integration
<img align="left" src="https://cdn.gyptazy.ch/images/proxmox-rebalancing-service-GUI-integration.jpg"/> PRS can also be directly be used from the Proxmox Web UI by installing the optional package `pve-proxmox-rebalancing-service-ui` package which has a dependency on the `proxmox-rebalancing-service` package. For the Web UI integration, it requires to be installed (in addition) on the nodes on the cluster. Afterwards, a new menu item is present in the HA chapter called `Rebalancing`. This chapter provides two possibilities:
* Rebalancing VM workloads
* Migrate VM workloads away from a defined node (e.g. maintenance preparation)

### Quick Start
The easiest way to get started is by using the ready-to-use packages that I provide on my CDN and to run it on a Linux Debian based system. This can also be one of the Proxmox nodes itself.

```
wget https://cdn.gyptazy.ch/files/amd64/debian/proxmox-rebalancing-service/proxmox-rebalancing-service_0.9.9_amd64.deb
dpkg -i proxmox-rebalancing-service-0.9.9.deb
# Adjust your config
vi /etc/proxmox-rebalancing-service/prs.conf
systemctl restart proxmox-rebalancing-service
systemctl status proxmox-rebalancing-service
```

### Logging
PRS uses the `SystemdHandler` for logging. You can find all your logs in your systemd unit log or in the journalctl.

## Motivation
As a developer managing a cluster of virtual machines for my projects, I often encountered the challenge of resource imbalance. Nodes within the cluster would become unevenly loaded, with some nodes being overburdened while others remained underutilized. This imbalance led to inefficiencies, performance bottlenecks, and increased operational costs. Frustrated by the lack of an adequate solution to address this issue, I decided to develop the Proxmox Rebalancing Service (PRS) to ensure better resource distribution across my clusters.

My primary motivation for creating PRS stemmed from my work on my BoxyBSD project, where I consistently faced the difficulty of maintaining balanced nodes while running various VM workloads but also on my personal clusters. The absence of an efficient rebalancing mechanism made it challenging to achieve optimal performance and stability. Recognizing the necessity for a tool that could gather and analyze resource metrics from both the cluster nodes and the running VMs, I embarked on developing PRS.

PRS meticulously collects detailed resource usage data from each node in a Proxmox cluster, including CPU load, memory usage, and local disk space utilization. It also gathers comprehensive statistics from all running VMs, providing a granular understanding of the workload distribution. With this data, PRS intelligently redistributes VMs based on memory usage, local disk usage, and CPU usage. This ensures that no single node is overburdened, storage resources are evenly distributed, and the computational load is balanced, enhancing overall cluster performance.

As an advocate of the open-source philosophy, I believe in the power of community and collaboration. By sharing solutions like PRS, I aim to contribute to the collective knowledge and tools available to developers facing similar challenges. Open source fosters innovation, transparency, and mutual support, enabling developers to build on each other's work and create better solutions together.

Developing PRS was driven by a desire to solve a real problem I faced in my projects. However, the spirit behind this effort was to provide a valuable resource to the community. By open-sourcing PRS, I hope to help other developers manage their clusters more efficiently, optimize their resource usage, and reduce operational costs. Sharing this solution aligns with the core principles of open source, where the goal is not only to solve individual problems but also to contribute to the broader ecosystem.

## References
Here you can find some overviews of references for and about the Proxmox Rebalancing Service.

| Description | Link |
|------|:------:|
| General introduction post to Proxmox Rebalancing Service | https://gyptazy.ch/blog/proxmox-rebalancing-service-rebalance-virtual-machines-across-nodes-in-a-cluster/ |
| Howto install and use the Proxmox Rebalancing Service | https://gyptazy.ch/howtos/howto-install-and-use-the-proxmox-rebalancing-service-to-rebalance-resources-in-a-proxmox-cluster/ |

## Packages
Ready to use packages can be found at:
* https://cdn.gyptazy.ch/files/amd64/debian/proxmox-rebalancing-service/
* https://cdn.gyptazy.ch/files/amd64/ubuntu/proxmox-rebalancing-service/
* https://cdn.gyptazy.ch/files/amd64/redhat/proxmox-rebalancing-service/
* https://cdn.gyptazy.ch/files/amd64/freebsd/proxmox-rebalancing-service/

## Misc
### Bugs
Bugs can be reported via the GitHub issue tracker [here](https://github.com/gyptazy/proxmox-rebalancing-service/issues). You may also report bugs via email or deliver PRs to fix them on your own. Therefore, you might also see the contributing chapter.

### Contributing
Feel free to add further documentation, to adjust already existing one or to contribute with code. Please take care about the style guide and naming conventions.

### Author(s)
* Florian Paul Azim Hoberg @gyptazy (https://gyptazy.ch)
Empty file added docs/01_Installation.md
Empty file.
Empty file added docs/02_Configuration.md
Empty file.
23 changes: 23 additions & 0 deletions docs/03_FAQ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## FAQ

### Could not import all dependencies
PRS requires the Python library `proxmoxer`. This can simply be installed by the most
system repositories. If you encounter this error message you simply need to install it.


```
# systemctl status proxmox-rebalancing-service
x proxmox-rebalancing-service.service - Proxmox Rebalancing Service
Loaded: loaded (/etc/systemd/system/proxmox-rebalancing-service.service; static)
Active: failed (Result: exit-code) since Sat 2024-07-06 10:25:16 UTC; 1s ago
Duration: 239ms
Process: 7285 ExecStart=/usr/bin/proxmox-rebalancing-service -c /etc/proxmox-rebalancing-service/prs.conf (code=exited, status=2)
Main PID: 7285 (code=exited, status=2)
CPU: 129ms
Jul 06 10:25:16 build01 systemd[1]: Started proxmox-rebalancing-service.service - Proxmox Rebalancing Service.
Jul 06 10:25:16 build01 proxmox-rebalancing-service[7285]: proxmox-rebalancing-service: Error: [python-imports]: Could not import all dependencies. Please install "proxmoxer".
```

Debian/Ubuntu: apt-get install python3-proxmoxer
If the package is not provided by your systems repository, you can also install it by running `pip3 install proxmoxer`.
14 changes: 14 additions & 0 deletions packaging/01_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
apt-get install rpm cmake make

mkdir packages
mkdir build
cd build
cmake ..
cpack -G DEB .
cpack -G RPM .
cp *.deb ../packages
cp *.rpm ../packages
cd ..
rm -rf build
echo "Packages created. Packages can be found in directory: packages"
41 changes: 41 additions & 0 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.16)
project(proxmox-rebalancing-service VERSION 0.9.9)

install(PROGRAMS ../proxmox-rebalancing-service DESTINATION /bin)
install(FILES ../prs.conf DESTINATION /etc/proxmox-rebalancing-service)
install(FILES proxmox-rebalancing-service.service DESTINATION /etc/systemd/system)

# General
set(CPACK_PACKAGE_NAME "proxmox-rebalancing-service")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/../README.md")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Florian Paul Azim <gyptazy> Hoberg <gyptazy@gyptazy.ch>")
set(CPACK_PACKAGE_CONTACT "Florian Paul Azim Hoberg <gyptazy@gyptazy.ch>")
set(CPACK_PACKAGE_VENDOR "gyptazy")

# RPM packaging
set(CPACK_PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_RPM_PACKAGE_SUMMARY "Proxmox Rebalancing Service - Rebalance VMs within a Proxmox cluster.")
set(CPACK_RPM_PACKAGE_DESCRIPTION "Proxmox Rebalancing Service - Rebalance VMs within a Proxmox cluster.")
set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/changelog_redhat")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_RPM_PACKAGE_LICENSE "GPL 3.0")
set(CPACK_RPM_PACKAGE_REQUIRES "python >= 3.2.0")

# DEB packaging
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_SUMMARY "Proxmox Rebalancing Service - Rebalance VMs within a Proxmox cluster.")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Proxmox Rebalancing Service - Rebalance VMs within a Proxmox cluster.")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/changelog_debian")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "python3")
set(CPACK_DEBIAN_PACKAGE_LICENSE "GPL 3.0")


# Install
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/postinst")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/postinst")
include(CPack)
14 changes: 14 additions & 0 deletions packaging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Build packages
Building the packages requires cmake, deb and rpm.
For building packages, simly run the following commands:

```
mkdir build
cd build
cmake ..
cpack -G RPM .
cpack -G DEB .
```

When running on Debian/Ubuntu you can directly call `01_package.sh`
to create your own packages.
5 changes: 5 additions & 0 deletions packaging/changelog_debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
proxmox-rebalancing-service (0.9.0) unstable; urgency=low

* Initial release of Proxmox Rebalancing Service.

-- Florian Paul Azim Hoberg <gyptazy@gyptazy.ch> Sun, 07 Jul 2024 05:38:41 -0200
2 changes: 2 additions & 0 deletions packaging/changelog_redhat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Sun Jul 07 2024 Florian Paul Azim Hoberg <gyptazy@gyptazy.ch>
- Initial release of Proxmox Rebalancing Service.
5 changes: 5 additions & 0 deletions packaging/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
useradd -m prs
chown prs:prs /etc/proxmox-rebalancing-service/prs.conf
chmod 600 /etc/proxmox-rebalancing-service/prs.conf
systemctl daemon-reload
6 changes: 6 additions & 0 deletions packaging/proxmox-rebalancing-service.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Unit]
Description=Proxmox Rebalancing Service

[Service]
ExecStart=/usr/bin/proxmox-rebalancing-service -c /etc/proxmox-rebalancing-service/prs.conf
User=prs
Loading

0 comments on commit ca18334

Please sign in to comment.