I&B Monitoring Platform documentation

Prometheus libvirt exporter

Installation of Prometheus libvirt exporter in production environment consists from following high level steps on your KVM/QEMU node:

  1. Install go lang environment;

  2. Install libvirt-dev environment;

  3. Install exporter;

  4. Configure firewall;

  5. Configure authentication and encryption;

  6. 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

Bash
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:

Bash
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:

Bash
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:

Bash
source ~/.bash_profile 

or

Bash
source ~/.bashrc 

or logout and login to shell

1.4 Verify installed go lang

Bash
go version

You should see in output:

go version go1.25.1 linux/amd64

Debian (Ubuntu)

1.5 Install go lang

Bash
sudo apt install golang-go

logout and login to shell

Bash
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)

Bash
sudo dnf install libvirt-devel

Debian (Ubuntu)

Bash
sudo apt install libvirt-dev

3. Install Prometheus libvirt exporter.

  1. Check latest version of code, on libvirt_exporter GitHub page.

  2. Download code of exporter.

Bash
wget https://github.com/Tinkoff/libvirt-exporter/archive/refs/tags/2.3.3.tar.gz
  1. Create directory /usr/local/bin/libvirt_exporter and untar exporter into it.

Bash
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
  1. Create prometheus user. If it already exist - go to step 6.

Fedora (RHEL, CentOS)

Bash
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)

Bash
sudo useradd -s /sbin/nologin prometheus --no-create-home
  1. Make prometheus user owner of libvirt_exporter directory.

Bash
sudo chown -hR prometheus:prometheus /usr/local/bin/libvirt_exporter
  1. Go to exporter directory.

Bash
cd /usr/local/bin/libvirt_exporter
  1. Build binary from downloaded go code.

Bash
go build

Your exporter ready to run and expose metrics for prometheus

4. Configure firewall

Configure firewall on resource

  1. 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

  1. Run libvirt_exporter

/usr/local/bin/libvirt_exporter/libvirt-exporter

In output you should see nothing

Check with browser if it is accessible at:

http://localhost:9177/metrics

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:

image-20250930-081944.png

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.