0x00

记录一次安装pve-exporter并且配置prometheus-operator的serviceMonitor。

prometheus-pve-exporter的作用是收集proxmox VE宿主机的状态并且提供一个接口供prometheus监控系统使用。

0x01 exporter安装

安装过程(python安装)

  1. 进入proxmox VE后台,进入节点的web shell

  2. 安装pip3

    apt install python3-pip
  3. 安装prometheus-pve-exporter

    pip3 install prometheus-pve-exporter
  4. 编写配置文件

    mkdir /etc/prometheus-pve-exporter
    nano /etc/prometheus-pve-exporter/pve.yml

    写入以下内容

    default:
    user: your-username
    password: your-password
  5. 编写启动脚本

    nano /etc/init.d/prometheus-pve-exporter

    写入以下内容

    #!/bin/sh
    pve_exporter /etc/prometheus-pve-exporter/pve.yml 9221 0.0.0.0
    exit 0
  6. 测试并且重启

    sh /etc/init.d/prometheus-pve-exporter &
    curl http://localhost:9221/

    如果获取到返回值说明启动成功。

    0x02 prometheus配置

    prometheus需要发现这个exporter。要让prometheus自动发现服务,需要添加一个ServiceMonitor,prometheus可以自动获取到ServiceMonitor,相当于添加了一个中转站。
    创建文件pve-monitor.yaml

apiVersion: v1
kind: Endpoints
metadata:
  name: pve-monitoring
  namespace: monitoring
subsets:
  - addresses:
      - ip: xxx.xxx.xxx.xxx # 一台运行pve_exporter的服务器IP
    ports:
      - name: metrics
        port: 9221
        protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    metrics: pve
  name: pve-monitoring
  namespace: monitoring
spec:
  ports:
    - port: 9221
      name: metrics
      protocol: TCP
  type: ClusterIP
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: pve-servicemonitor
  labels:
    team: data-provider # 用于让prometheus发现这个服务,需要手动设置
  namespace: monitoring
spec:
  endpoints:
    - interval: 30s
      port: metrics
      path: "/pve"
      params:
        - xxx.xxx.xxx.xxx # 从哪些机器获取性能指标
        - xxx.xxx.xxx.xxx 
  namespaceSelector:
    matchNames:
      - monitoring
  selector:
    matchLabels:
      metrics: pve

应用

kaf pve-monitor.yaml