Ignore endpoint when prometheus scrap metrics

2/11/2020

Each k8s pods has /metrics endpoint in my cluster. Except one. I'm trying to ignore that pode by label, It is possible?

I have the following scrap config

   - job_name: business-service-metrics
      metrics_path: /metrics
      kubernetes_sd_configs:
      - role: pod
      relabel_configs:
      - action: replace
        source_labels:
        - __meta_kubernetes_namespace
        target_label: kubernetes_namespace
      - action: replace
        source_labels:
        - __meta_kubernetes_pod_container_name
        target_label: kubernetes_name
      - action: replace
        source_labels:
        - __meta_kubernetes_pod_label_app
        target_label: service_type
      - action: replace
        source_labels:
        - __meta_kubernetes_pod_label_service
        target_label: service_name
      - action: keep
        regex: true
        source_labels:
        - __meta_kubernetes_pod_annotation_prometheus_io_scrape
      - action: replace
        regex: ([^:]+)(?::\d+)?;(\d+)
        replacement: $1:$2
        source_labels:
        - __address__
        - __meta_kubernetes_pod_annotation_prometheus_io_port
        target_label: __address__
      - action: keep
        regex: (.+)
        source_labels:
        - __meta_kubernetes_pod_label_service

How to ignore pod with label demo? I believe that I should change something in regex but no experience. Please help.

-- Chebur
kubernetes
metrics
prometheus

0 Answers