Prometheus. Proxmox via Prometheus monitoring

Материал из Wiki
Перейти к навигации Перейти к поиску

Links

https://community.hetzner.com/tutorials/proxmox-prometheus-metrics

PVE Server

Create users

We will create a dedicated Proxmox VE user because anonymous data collection is not permitted. This user will have read-only permissions.

  pve-exporter@pve — a username of a new Proxmox VE user.   -password <password> — set a password for that user. Replace <password> with the actual password.

pveum user add pve-exporter@pve -password <password> Add the role PVEAuditor for the newly created user:

  / — first argument is an access control path, everything in this case.

  -user pve-exporter@pve — specify the user.

  -role PVEAuditor — specify role for that user.

pveum acl modify / -user pve-exporter@pve -role PVEAuditor Create Linux User

  -s /bin/false — set login shell to /bin/false in order to disable interactive login.   pve-exporter — user's login name.

useradd -s /bin/false pve-exporter

Create Virtual Environment

The Prometheus Proxmox VE Exporter is written in Python, and we will install it within a so called venv (virtual environment). The use of such a virtual environment makes Python dependency handling much easier compared to a regular installation with pip.

apt update

apt install -y python3-venv

And create a new virtual environment

python3 -m venv /opt/prometheus-pve-exporter

Install Prometheus Proxmox VE Exporter

Activate the virtual environment

source /opt/prometheus-pve-exporter/bin/activate

Check if (prometheus-pve-exporter) is present in front of your command line prompt before executing the next command.

Install prometheus-pve-exporter

pip install prometheus-pve-exporter

On Debian 10, the error message Failed building wheel for MarkupSafe may be displayed. This is not an issue, simply verify that everything has been installed by executing the command again. It should finish in very short time and all lines should begin with Requirement already satisfied.

Finally, leave the virtual environment by executing deactivate

deactivate

Configure Prometheus Proxmox VE Exporter

nano /etc/prometheus/pve.yml

default:
    user: pve-exporter@pve
    password: <password>
    verify_ssl: false

chown -v root.pve-exporter /etc/prometheus/pve.yml

chmod -v 640 /etc/prometheus/pve.yml

Create Systemd Service

nano /etc/systemd/system/prometheus-pve-exporter.service

[Unit]
Description=Prometheus Proxmox VE Exporter
Documentation=https://github.com/prometheus-pve/prometheus-pve-exporter

[Service]
Restart=always
User=pve-exporter
ExecStart=/opt/prometheus-pve-exporter/bin/pve_exporter /etc/prometheus/pve.yml

[Install]
WantedBy=multi-user.target

systemctl daemon-reload

systemctl enable prometheus-pve-exporter.service

systemctl restart prometheus-pve-exporter.service

Verify that pve_explorer is listening to TCP port 9221

netstat -luptn

    ...
    LISTEN 0      128          0.0.0.0:9221
    ...

Prometheus server

curl --silent http://<pve_IP>:9221/pve | grep pve_version_info

    ...
    # HELP pve_version_info Proxmox VE version info
    # TYPE pve_version_info gauge
    pve_version_info{release="7.2",repoid="963997e8",version="7.2-15"} 1.0
    ...

Extend the scrape_config section in your existing Prometheus configuration with the following lines:

nano /etc/prometheus/prometheus.yml

...
  - job_name: 'pve-exporter'
    static_configs:
      - targets:
        - 127.0.0.1:9221
    metrics_path: /pve
    params:
      module: [default]

systemctl restart prometheus

Import Grafana Dashboard

Log in to your Grafana instance, add new Dashboards, press the import button, insert the ID 10347 and click load (You can find the dashboard here: https://grafana.com/grafana/dashboards/10347)

   -OR-

Download proxmox-via-prometheus_rev5.json from https://grafana.com/grafana/dashboards/10347 and import it.