首页 > 解决方案 > 如何标记 Prometheus blackbox_exporter 端点

问题描述

我有一个带有 Prometheus 的 k8s 集群和一些带有 Web 应用程序的 Pod。我想从这些网络应用程序中收集指标。我为此使用了Prometheus blackbox_exporter

我配置了服务监视器,部署,由普罗米修斯操作员工作。Prometheus 收集指标,但我无法区分它们。例如,
probe_success{endpoint="http-metrics",instance="10.20.0.105:9115",job="prometheus-blackbox-exporter",namespace="staging",pod="prometheus-blackbox-exporter-66fb58ff97-pd6lk",service="prometheus-blackbox-exporter"}

我应该怎么做才能为每个端点添加额外的标签?

如何将target等标签添加到 probe_success 指标?

在此处输入图像描述

  blackbox.yaml: |
    modules:
      http_2xx:
        prober: http
        http:
          preferred_ip_protocol: "ipv4"
          tls_config:
            ca_file: "/config/my.pem"
      http_post_4xx:
        prober: http
        http:
          method: POST
          valid_status_codes: [400,404,401,403]
          headers:
            Content-Type: application/json
          body: '{"nonsense"}'
          preferred_ip_protocol: "ipv4"
          tls_config:
            ca_file: "/config/my.pem"

服务是

---
kind: Service
apiVersion: v1
metadata:
  name: prometheus-blackbox-exporter
  labels:
    app.kubernetes.io/name: prometheus-blackbox-exporter
    name: prometheus-blackbox-exporter
    monitoring: "true"
spec:
  type: ClusterIP
  ports:
    - name: http-metrics
      port: 9115
      protocol: TCP
  selector:
    app.kubernetes.io/name: prometheus-blackbox-exporter

---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: prometheus-blackbox-exporter
  labels: {}
spec:
  selector:
    matchLabels:
      name: prometheus-blackbox-exporter
  endpoints:
    - port: http-metrics
      metricRelabelings:
        - sourceLabels: [__address__]
          targetLabel: __param_target
        - sourceLabels: [__param_target]
          targetLabel: instance
        - sourceLabels: [__address__]
          replacement: prometheus-blackbox-exporter:9115
      path: /probe
      params:
        target:
          - "web:3000"
        module:
          - "http_2xx"

    - port: http-metrics
      metricRelabelings:
        - sourceLabels: [__address__]
          targetLabel: __param_target
        - sourceLabels: [__param_target]
          targetLabel: instance
        - sourceLabels: [__address__]
          replacement: prometheus-blackbox-exporter:9115
      path: /probe
      params:
        target:
          - "api:8080/api/v1/login"
        module:
          - "http_post_4xx"

标签: prometheusprometheus-operatorprometheus-blackbox-exporter

解决方案


弄清楚了:

port: snmp-exporter
    params:
      module:
      - if_mib # Select which SNMP module to use
      target:
      - 192.168.0.0
    path: "/snmp"
    targetPort: 9116
    honorLabels: true
    relabelings:
            #- action: labelmap
      - sourceLabels: [__param_target]
        #regex: '.*'
        #action: replace
        targetLabel: instance

推荐阅读