使用 proxmox-pve-exporter 监控Proxmox VE
PVE 原生支持 Graphite 或者 InfluxDB 作为指标数据的存储,这俩我还没折腾过,本文主要围绕着prometheus-pve-exporter来写,类似于node_exporter 这里就不再多说了。
安装 proxmox-pve-exporter
[card title=”说明” color=”warning”]
这里我将 proxmox-pve-exporter 安装到单独的服务器,而不是 pve宿主机,,这样可以通过一个 exporter 去监控多台 pve 主机,如果只有一台机器的话直接在pve主机安装就行。。。
[/card]
GitHub地址:https://github.com/prometheus-pve/prometheus-pve-exporter
安装 exporter,如果没有pip3的话需要先安装python3-pip
1 | pip3 install prometheus-pve-exporter -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple |
安装完成后可以通过 pve_exporter -h
查看帮助信息
帮助命令机翻:
1 | 用法:pve_exporter [-h] [--collector.status | --no-collector.status] |
也可以通过 Docker 安装
1 | docker run --init --name prometheus-pve-exporter -d -p 127.0.0.1:9221:9221 -v /path/to/pve.yml:/etc/prometheus/pve.yml prompve/prometheus-pve-exporter |
配置监控用户
出于安全原因,必须添加具有只读访问权限的用户(PVEAuditor 角色)来收集指标。
在所有的PVE主机创建一个用户
1 | pveum useradd monitor@pve -comment "monitor for exporter" # 创建用户 |
为 prometheus 用户分配 PVEAuditor 监控角色的权限
1 | pveum aclmod / -user monitor@pve -role PVEAuditor |
配置 proxmox-pve-exporter
在安装了 proxmox-pve-exporter 的主机中创建一个配置文件,用于定义PVE主机的用户名,密码,就是上面创建的用户
nano /etc/prometheus/pve.yml
1 | default: |
配置开机自启
1 | tee /etc/systemd/system/prometheus-pve-exporter.service<<EOF |
1 | systemctl daemon-reload && systemctl enable --now prometheus-pve-exporter.service |
默认端口 9221
访问 exporter http://ip:9221
这里会让你访问/pve?target=1.2.3.4
,其中 target=
是你的PVE主机IP地址,如果是在pve主机搭建的 prometheus-pve-exporter ip填 127.0.0.1 即可,我这种方法适合需要监控多台PVE主机的场景
查看监控指标
Prometheus 配置
单台机器
1 | - job_name: 'pve' |
多台机器,使用relabel_configs
重写目标地址
1 | - job_name: 'pve' |
配置完成后重启普罗米修斯,并进行验证
配置Grafana仪表盘
这里推荐使用 10347 https://grafana.com/grafana/dashboards/10347-proxmox-via-prometheus/
通过/dashboard/import 导入即可
演示地址:https://grafana.wanghaoyu.com.cn/d/Dp7Cd57Zza/proxmox-via-prometheus