Is there a way to configure prometheus to ignore scraping metrics for all the resources belonging to a particular namespace? I am not able to figure it out by reading the documentation.
Asked
Active
Viewed 4,920 times
1 Answers
6
You can drop targets with relabel_config
by using drop
action. From the documentation:
drop
: Drop targets for whichregex
matches the concatenatedsource_labels
.
Example:
relabel_configs:
# This will ignore scraping targets from 'ignored_namespace_1',
# 'ignored_namespace_2', and 'ignored_namespace_N'.
- source_labels: [__meta_kubernetes_namespace]
action: drop
regex: ignored_namespace_1|ignored_namespace_2|ignored_namespace_N

anemyte
- 17,618
- 1
- 24
- 45
-
I tried using this config and it's now working. which role did you use? – Von Oct 25 '21 at 07:26
-
@Von `__meta_kubernetes_namespace` appears for roles that represent namespaced objects: service, ingress, endpoints, and pod. Nodes are not namespaced and so there's no namespace label. – anemyte Oct 25 '21 at 07:36
-
I Am trying to exclude namespace from being scraped by prometheus by using below config. But the metrcis still appears in prometheus. scrape_configs: - job_name: 'kubernetes-pods' relabel_configs: - source_labels: [__meta_kubernetes_namespace] action: drop regex:
– Von Oct 25 '21 at 09:09 -
@Von Consider asking a question with it. Bring all the details (e.g. examples of those metrics). – anemyte Oct 25 '21 at 09:25
-
1Is it possible to do the oposite? Like include only specific metrics by regex or list – alext Sep 30 '22 at 15:13
-
@sem10 yep, use `keep` instead of `drop`, everything else is the same. – anemyte Sep 30 '22 at 15:52