Installation of Prometheus libvirt exporter in production environment consists from following high level steps on your KVM/QEMU node:
-
Install go lang environment;
-
Install libvirt-dev environment;
-
Install exporter;
-
Configure firewall;
-
Configure authentication and encryption;
-
Configure service for autostart and restart.
1. Install go lang.
Fedora (RHEL, CentOS)
1.1 Go to the official Golang download page (https://go.dev/dl/ ) and find the latest version compatible with CentOS/RHEL
wget https://go.dev/dl/go1.25.1.linux-amd64.tar.gz
1.2 Once the download is complete, extract the Golang tarball to /usr/local:
sudo tar -C /usr/local -xzf go1.25.1.linux-amd64.tar.gz
1.3 For Go to function properly, you need to set the environment variables.. Commonly you need to set 3 environment variables as GOROOT, GOPATH and PATH. Add these lines to your ~/.bash_profile or ~/.bashrc file:
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
After adding these lines, source your profile to apply the changes:
source ~/.bash_profile
or
source ~/.bashrc
or logout and login to shell
1.4 Verify installed go lang
go version
You should see in output:
go version go1.25.1 linux/amd64
Debian (Ubuntu)
1.5 Install go lang
sudo apt install golang-go
logout and login to shell
go version
You should see in output:
go version go1.19.8 linux/amd64
2. Install libvirt-dev.
To install the libvirt development files you need run:
Fedora (RHEL, CentOS)
sudo dnf install libvirt-devel
Debian (Ubuntu)
sudo apt install libvirt-dev
3. Install Prometheus libvirt exporter.
-
Check latest version of code, on libvirt_exporter GitHub page.
-
Download code of exporter.
wget https://github.com/Tinkoff/libvirt-exporter/archive/refs/tags/2.3.3.tar.gz
-
Create directory /usr/local/bin/libvirt_exporter and untar exporter into it.
sudo mkdir -p /usr/local/bin/libvirt_exporter
sudo tar xvfz 2.3.3.tar.gz -C /usr/local/bin/libvirt_exporter --strip-components=1
-
Create prometheus user. If it already exist - go to step 6.
Fedora (RHEL, CentOS)
sudo useradd -M -s /sbin/nologin prometheus
-
-M(or--no-create-home): This option prevents the creation of a home directory for the new user; -
-s /sbin/nologin: This option sets the user's login shell to/sbin/nologin. This effectively prevents the user from interactively logging into the system. While the user won't have a password set, this further ensures they cannot log in.
Debian (Ubuntu)
sudo useradd -s /sbin/nologin prometheus --no-create-home
-
Make prometheus user owner of libvirt_exporter directory.
sudo chown -hR prometheus:prometheus /usr/local/bin/libvirt_exporter
-
Go to exporter directory.
cd /usr/local/bin/libvirt_exporter
-
Build binary from downloaded go code.
go build
Your exporter ready to run and expose metrics for prometheus
4. Configure firewall
Configure firewall on resource
-
libvirt The exporter uses port 9177 by default, but we will organize access through a reverse proxy for authentication and encryption protection, so we allow access through port 443.
Fedora (RHEL, CentOS)
sudo firewall-cmd --zone=public --add-port=443/tcp --permanent
sudo systemctl reload firewalld
Check firewall configuration
sudo firewall-cmd --list-all
You should see in output:
ports: 443/tcp
Debian (Ubuntu)
sudo ufw allow 443
You should see in output:
Rules updated
Rules updated (v6)
Check firewall configuration
sudo ufw status
You should see in output:
To Action From
-- ------ ----
443 ALLOW Anywhere
its good
5. Configure authentication and encryption for exporter
Do the steps described in Exporters configuration → Install NGINX as reverse proxy to add basic auth and tls encription for exporters not support this out of box section, in Nginx configuration we will use http://localhost:9177 in “sting proxy_pass http://localhost:9221;”.
6. Check configuration
-
Run libvirt_exporter
/usr/local/bin/libvirt_exporter/libvirt-exporter
In output you should see nothing
Check with browser if it is accessible at:
After entering exporter’s user name and password you should see page like this:
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0.00012087
...
Stop libvirt exporter with Ctrl-c in terminal where you run it.
Make libvirt_exporter service for autostart and restart.
Create file with your preferred text editor, for example nano …
sudo nano /etc/systemd/system/libvirt_exporter.service
… and paste following text into it.
[Unit]
Description=libvirt Exporter
[Service]
User=prometheus
ExecStart=/usr/local/bin/libvirt_exporter/libvirt-exporter
[Install]
WantedBy=multi-user.target
Save file and exit editor.
Start service …
sudo systemctl daemon-reload
sudo systemctl start libvirt_exporter
sudo systemctl enable libvirt_exporter
… and check
sudo systemctl status libvirt_exporter
You should see following output similar to:
In case of any problem, you should view log entries for service:
journalctl -u libvirt_exporter.service -e
Now libvirt exporter is ready to accept data and then expose it to Prometheus.