Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
/ pbs-exporter Public archive

Bash script that uploads proxmox backup server API info to prometheus' pushgateway.

License

Notifications You must be signed in to change notification settings

rare-magma/pbs-exporter

Repository files navigation

pbs-exporter

I no longer use proxmox backup server so development of this tool has ceased. Feel free to fork it

Bash script that uploads proxmox backup server API info to prometheus' pushgateway on a daily basis.

Dependencies

  • curl
  • jq
  • Optional: make - for automatic installation support

Relevant documentation

Installation

With Docker

docker-compose

  1. Configure pbs_exporter.conf (see the configuration section below).

  2. Run it.

    docker compose up --detach

docker build & run

  1. Build the docker image.

    docker build . --tag pbs-exporter
  2. Configure pbs_exporter.conf (see the configuration section below).

  3. Run it.

    docker run --rm --init --tty --interactive --volume $(pwd):/app localhost/pbs-exporter

As normal user

With the Makefile

For convenience, you can install this exporter with the following command or follow the manual process described in the next paragraph.

make install-user
$EDITOR $HOME/.config/pbs_exporter.conf

Manually

  1. Copy pbs_exporter.sh to $HOME/.local/bin/ and make it executable.

  2. Copy pbs_exporter.conf to $HOME/.config/, configure it (see the configuration section below) and make it read only.

  3. Edit pbs-exporter.service and change the following lines:

ExecStart=/usr/local/bin/pbs_exporter.sh
EnvironmentFile=/etc/pbs_exporter.conf

to

ExecStart=/home/%u/.local/bin/pbs_exporter.sh
EnvironmentFile=/home/%u/.config/pbs_exporter.conf
  1. Copy the systemd unit and timer to $HOME/.config/systemd/user/:
cp pbs-exporter.* $HOME/.config/systemd/user/
  1. and run the following command to activate the timer:
systemctl --user enable --now pbs-exporter.timer

It's possible to trigger the execution by running manually:

systemctl --user start pbs-exporter.service
As root

With the Makefile

For convenience, you can install this exporter with the following command or follow the manual process described in the next paragraph.

sudo make install
sudoedit /etc/pbs_exporter.conf

Manually

  1. Copy pbs_exporter.sh to /usr/local/bin/ and make it executable.

  2. Copy pbs_exporter.conf to /etc/, configure it (see the configuration section below) and make it read only.

  3. Copy the systemd unit and timer to /etc/systemd/system/:

sudo cp pbs-exporter.* /etc/systemd/system/
  1. and run the following command to activate the timer:
sudo systemctl enable --now pbs-exporter.timer

It's possible to trigger the execution by running manually:

sudo systemctl start pbs-exporter.service

Config file

The config file has a few options:

PBS_API_TOKEN_NAME='user@pam!prometheus'
PBS_API_TOKEN='123e4567-e89b-12d3-a456-426614174000'
PBS_URL='https://pbs.example.com'
PUSHGATEWAY_URL='https://pushgateway.example.com'
  • PBS_API_TOKEN_NAME should be the value in the "Token name" column in the Proxmox Backup Server user interface's Configuration - Access Control - Api Token page.
  • PBS_API_TOKEN should be the value shown when the API Token was created.
    • This token should have at least the Datastore.Audit access role assigned to it and the path set to /datastore.
  • PBS_URL should be the same URL as used to access the Proxmox Backup Server user interface
  • PUSHGATEWAY_URL should be a valid URL for the push gateway.

Troubleshooting

As normal user

Run the script manually with bash set to trace:

bash -x $HOME/.local/bin/pbs_exporter.sh

Check the systemd service logs and timer info with:

journalctl --user --unit pbs-exporter.service
systemctl --user list-timers
As root

Run the script manually with bash set to trace:

sudo bash -x /usr/local/bin/pbs_exporter.sh

Check the systemd service logs and timer info with:

journalctl --unit pbs-exporter.service
systemctl list-timers

Exported metrics per PBS store

The following metrics are available for all stores currently not in maintenance mode:

  • pbs_available: The available bytes of the underlying storage.
  • pbs_size: The size of the underlying storage in bytes.
  • pbs_used: The used bytes of the underlying storage.
  • pbs_snapshot_count: The total number of backups.
  • pbs_snapshot_vm_count: The total number of backups per VM.

Exported metrics example

# HELP pbs_available The available bytes of the underlying storage.
# TYPE pbs_available gauge
# HELP pbs_size The size of the underlying storage in bytes.
# TYPE pbs_size gauge
# HELP pbs_used The used bytes of the underlying storage.
# TYPE pbs_used gauge
# HELP pbs_snapshot_count The total number of backups.
# TYPE pbs_snapshot_count gauge
# HELP pbs_snapshot_vm_count The total number of backups per VM.
# TYPE pbs_snapshot_vm_count gauge
pbs_available {host="pbs.example.com", store="store2"} 567317757952
pbs_size {host="pbs.example.com", store="store2"} 691587252224
pbs_used {host="pbs.example.com", store="store2"} 124269494272
pbs_snapshot_count {host="pbs.example.com", store="store2"} 295
pbs_snapshot_vm_count {host="pbs.example.com", store="store2", vm_id="101"} 11
pbs_snapshot_vm_count {host="pbs.example.com", store="store2", vm_id="102"} 12
pbs_snapshot_vm_count {host="pbs.example.com", store="store2", vm_id="103"} 10

Uninstallation

As normal user

With the Makefile

For convenience, you can uninstall this exporter with the following command or follow the process described in the next paragraph.

make uninstall-user

Manually

Run the following command to deactivate the timer:

systemctl --user disable --now pbs-exporter.timer

Delete the following files:

$HOME/.local/bin/pbs_exporter.sh
$HOME/.config/pbs_exporter.conf
$HOME/.config/systemd/user/pbs-exporter.timer
$HOME/.config/systemd/user/pbs-exporter.service
As root

With the Makefile

For convenience, you can uninstall this exporter with the following command or follow the process described in the next paragraph.

sudo make uninstall

Manually

Run the following command to deactivate the timer:

sudo systemctl disable --now pbs-exporter.timer

Delete the following files:

/usr/local/bin/pbs_exporter.sh
/etc/pbs_exporter.conf
/etc/systemd/system/pbs-exporter.timer
/etc/systemd/system/pbs-exporter.service

Credits

This project takes inspiration from the following: