配置 prometheus-operator 以从 blackbox-operator 抓取静态 icmp 目标

Configure prometheus-operator to scrape static icmp targets from blackbox-operator

我需要如何配置 monitoring.coreos.com/v1 Probe 来检测我的 prometheus-operator 从定义的目标列表中收集 icmp 指标?

这假设您已经安装了 prometheus- 和 blackbox-exporter,如下所示:

helm install prometheus prometheus-community/kube-prometheus-stack -n monitoring --create-namespace
helm install prometheus-blackbox-exporter prometheus-community/prometheus-blackbox-exporter -n monitoring

首先,您需要在值文件中启用黑盒导出器的 icmp 模块,例如blackbox-exporter.yml:

config:
  modules:
    icmp:
      prober: icmp
      icmp:
        preferred_ip_protocol: ip4

allowIcmp: true

应用配置:

helm upgrade prometheus-blackbox-exporter prometheus-community/prometheus-blackbox-exporter -f blackbox-exporter.yml

那么你可以这样定义 Probe:

apiVersion: monitoring.coreos.com/v1
kind: Probe
metadata:
  name: blackbox-probe-icmp
  namespace: monitoring
  labels:
    release: prometheus
spec:
  jobName: icmp
  interval: 1m
  scrapeTimeout: 5s
  module: icmp
  prober:
    url: prometheus-blackbox-exporter:9115
  targets:
    staticConfig:
      static:
        - 192.168.1.1
        - 8.8.8.8