You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OTEL Collector Prometheus接收器配置异常:误抓未指定注解的Pod指标

问题排查与解决方案

你的配置中,核心问题在于relabel规则的正则匹配不够精确,同时存在一处标签映射的错误,导致带有prometheus.io/scrape=false的Pod未被正确过滤,且Pod名称标签采集错误。

具体修复步骤

1. 精确匹配scrape=true注解

将第一个keep规则的正则表达式改为^true$,确保只精确匹配字符串"true",避免因意外的部分匹配导致不符合条件的Pod被保留:

- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
  action: keep
  regex: ^true$

2. 显式丢弃scrape=false的Pod

添加一条drop规则,主动过滤带有prometheus.io/scrape=false注解的Pod,作为双重保险:

- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
  action: drop
  regex: ^false$

3. 修正Pod名称标签映射

原配置中最后一条规则的source_labels错误使用了__meta_kubernetes_host_name(节点名称),应改为__meta_kubernetes_pod_name才能正确采集Pod名称:

- source_labels: [__meta_kubernetes_pod_name]
  action: replace
  target_label: kubernetes_pod_name

4. 配置验证与日志排查

  • 用命令检查配置合法性:
    otelcol-contrib config check --config your-config.yaml
    
  • 查看OTEL Collector的debug日志,搜索relabel关键字,观察哪些Pod被标记为保留/丢弃,定位具体匹配异常。

完整修复后的relabel_configs片段

relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
  action: keep
  regex: ^true$
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
  action: drop
  regex: ^false$
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scheme]
  action: replace
  target_label: __scheme__
  regex: (https?)
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
  action: replace
  target_label: __metrics_path__
  regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
  action: replace
  target_label: __address__
  regex: (.+)(?::\d+);(\d+)
  replacement: $1:$2
- action: labelmap
  regex: __meta_kubernetes_pod_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
  action: replace
  target_label: namespace
- source_labels: [__meta_kubernetes_pod_name]
  action: replace
  target_label: kubernetes_pod_name

内容的提问来源于stack exchange,提问作者Alpa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 05:25:27