Skip to content

Instantly share code, notes, and snippets.

@stan1ey-shen
Last active March 4, 2025 07:36
Show Gist options
  • Save stan1ey-shen/9e8a48f86c4070d1096aef20353cf753 to your computer and use it in GitHub Desktop.
Save stan1ey-shen/9e8a48f86c4070d1096aef20353cf753 to your computer and use it in GitHub Desktop.
Start PVE exporter

Grafana 監控 PVE

PVE 設定

  1. 在 PVE shell 內新增 PVE 使用者:
    pveum user add pve-exporter@pve -password "password"
    並且設定權限
    pveum acl modify / -user pve-exporter@pve -role PVEAuditor
    image
  2. 在 PVE shell 產生一個 API token:
    pveum user token add pve-exporter@pve exporter
  3. 在 PVE shell 產生一個使用者, 用來執行服務:
    useradd -s /bin/false pve-exporter
  4. 在 PVE shell 安裝 python3-venv, 並且裝上 prometheus-pve-exporter:
    apt update
    apt install -y python3-venv
    python3 -m venv /opt/Prometheus-pve-exporter
    source /opt/Prometheus-pve-exporter/bin/activate
    pip install Prometheus-pve-exporter
    deactivate
  5. 依據 prometheus-pve-exporter 需求, 將第2步產生的 API Token 寫到 config - /etc/prometheus/pve.yml:
    default:
      user: pve-exporter@pve
      token_name: exporter
      token_value: ...
      verify_ssl: false
  6. 新增一個 service 執行 prometheus-pve-exporter - /etc/systemd/system/pve_exporter.service:
    [Unit]
    Description=PVE Exporter
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=pve-exporter
    Type=simple
    ExecStart=/opt/Prometheus-pve-exporter/bin/pve_exporter --web.listen-address=[::]:9221
    
    [Install]
    WantedBy=multi-user.target
  7. 啟動服務:
    systemctl daemon-reload
    systemctl enable --now pve_exporter
    systemctl status pve_exporter
  8. 測試:
    curl http://localhost:9221/metrics
    curl http://localhost:9221/pve

Prometheus 設定

新增 config 抓 PVE exporter:

scrape_configs:
  - job_name: 'pve'
    static_configs:
      - targets:
        - <PVE_HOST>:9221
    metrics_path: /pve
    params:
      module: [default]
      cluster: ['1']
      node: ['1']

Grafana 設定

匯入 dashboard - Proxmox via Prometheus ID: 10347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment