[Relabel} For specific metric, persist only metrics coming from particular namespace and ignore rest

29 views
Skip to first unread message

learner

unread,
Jul 30, 2024, 4:40:01 AM7/30/24
to Prometheus Users
Hi Team,

I have scrape job called - job_name: 'kubernetes-pods', there are so many metrics being  push into prometheus. But i have this bit tricky requirement. As i want to store all metrics but for specific metric i.e envoy_cluster_upstream_cx_connect_ms_bucket i want to store this metrics only from specific namespace and ignore rest other namespace.

Note: if i use keep then it will drop all other metrics on job kubernetes-pods. So i don't want that. And i use drop then i have to provide whole list of namespaces which is not dynamic.



Brian Candler

unread,
Jul 30, 2024, 8:12:06 AM7/30/24
to Prometheus Users
Use a temporary label to give the logic "drop if metric name is X and namespace is not Y"

Roughly like this (untested):

- source_labels: [namespace]
  regex: 'my_interesting_namespace'
  target_label: __tmp_keep_namespace
  replacement: '1'

- source_labels: [__name__, __tmp_keep_namespace]
  regex: 'envoy_cluster_upstream_cx_connect_ms_bucket;'
  action: drop

- regex: __tmp_keep_namespace
  action: labeldrop
Reply all
Reply to author
Forward
0 new messages