【问题标题】:how to label Prometheus blackbox_exporter endpoints如何标记 Prometheus blackbox_exporter 端点
【发布时间】:2021-03-26 01:10:15
【问题描述】:

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

我配置了服务监视器,部署,由 prometheus 操作员工作。 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"

【问题讨论】:

    标签: prometheus prometheus-operator prometheus-blackbox-exporter


    【解决方案1】:

    想通了:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-18
      • 2018-05-02
      • 2020-02-07
      • 1970-01-01
      • 2019-07-07
      • 2020-11-08
      相关资源
      最近更新 更多