如何在Prometheus-Kube-Stack中全局配置labeldrop移除指定标签?
在Prometheus Kube-Stack中全局应用labeldrop移除指定标签
你不需要逐个给抓取任务添加labeldrop规则,通过kube-prometheus-stack的Helm配置可以实现全局生效:
方法1:使用globalRelabelings全局配置
在你的Helm values.yaml文件中添加以下配置,该规则会自动应用到所有抓取任务的指标上:
prometheus: prometheusSpec: globalRelabelings: - action: labeldrop regex: (prometheus_replica|prometheus)
执行Helm升级命令使配置生效:
helm upgrade -f your-values.yaml prometheus-kube-stack prometheus-community/prometheus-kube-stack
验证配置是否生效
- 访问Prometheus UI,进入
Status > Configuration页面 - 检查任意scrape任务的
relabel_configs,确认已包含上述labeldrop规则 - 直接查询任意指标,验证
prometheus_replica和prometheus标签已被移除
备选方案(适配旧版本kube-stack)
如果你的kube-prometheus-stack版本未支持globalRelabelings,可以通过注入全局metric_relabel规则实现:
prometheus: prometheusSpec: additionalScrapeConfigs: - job_name: 'global-metric-cleanup' scrape_interval: 1m metrics_path: '/metrics' static_configs: - targets: ['localhost:9090'] metric_relabel_configs: - action: labeldrop regex: (prometheus_replica|prometheus)
不过这种方式不如globalRelabelings直接,优先推荐第一种方法。
内容的提问来源于stack exchange,提问作者yershalom
相关产品推荐
相关产品推荐

