Home > Software design >  Exclude Kubernetes namespaces from prometheus scraping
Exclude Kubernetes namespaces from prometheus scraping

Time:10-28

I have deployed Prometheus using the community helm chart and would like to scrape the metrics from a specific namespace and drop the metrics from all the other namespaces. I have used the below scrape config, but it doesn't seem to work. Also tried using Drop action.

    - job_name: 'kubernetes-pods'
      kubernetes_sd_configs:
        - role: node
      relabel_configs:
        - action: keep
          source_labels: [__meta_kubernetes_namespace]
          target_label: accounts 

CodePudding user response:

Try this:

- job_name: 'kubernetes-pods'
  kubernetes_sd_configs:
  - role: endpoints
  namespaces:
    names:
    - my-namespace-to-monitor

CodePudding user response:

I found something like this: https://www.robustperception.io/dropping-metrics-at-scrape-time-with-prometheus

So I would try changing the example from the post to something like this:

scrape_configs:
  - job_name: 'kubernetes-pods'
    kubernetes_sd_configs:
      - role: node
    metric_relabel_configs:
      - source_labels: [ __meta_kubernetes_namespace ]
        regex: 'accounts'
        action: drop
  • Related