首先给目标pod打上以下标签:

    prometheus.io/path: metrics #监控路径
    prometheus.io/port: '9617' #监控端口
    prometheus.io/scrape: 'true'#是否监控

再给Prometheus配置文件添加以下规则

    - job_name: 'adguard-home-export'
      kubernetes_sd_configs:
      - role: pod
        namespaces:
          names:
          - public-services
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_prometheus_io_scrape]
        action: keep
        regex: true
      - source_labels: [__meta_kubernetes_pod_label_prometheus_io_scheme]
        action: replace
        target_label: __scheme__
        regex: (https?)
      - source_labels: [__meta_kubernetes_pod_label_prometheus_io_path]
        action: replace
        target_label: __metrics_path__
        regex: (.+)
      - source_labels: [__address__, __meta_kubernetes_pod_label_prometheus_io_port]
        action: replace
        target_label: __address__
        regex: ([^:]+)(?::\d+)?;(\d+)
        replacement: $1:$2
      - source_labels: [__meta_kubernetes_service_name]
        regex: prometheus-server
        action: drop
Last modification:May 5, 2022
如果觉得我的文章对你有用,请随意赞赏