2

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 
Von
  • 119
  • 1
  • 1
  • 9
  • You need to use `regex: accounts` instead of `target_label: accounts` for `keep` action to work. – anemyte Oct 26 '21 at 06:03
  • Does this answer your question? [Monitor only one namespace metrics - Prometheus with Kubernetes](https://stackoverflow.com/questions/59070150/monitor-only-one-namespace-metrics-prometheus-with-kubernetes) – moonkotte Oct 26 '21 at 14:20

2 Answers2

0

Try this:

- job_name: 'kubernetes-pods'
  kubernetes_sd_configs:
  - role: endpoints
  namespaces:
    names:
    - my-namespace-to-monitor
SYN
  • 4,476
  • 1
  • 20
  • 22
0

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
Cloudziu
  • 475
  • 3
  • 8