【问题标题】:Unable to relabel Prometheus pod scrape label __address__ if pod doesn't declare containerport如果 pod 未声明 containerport,则无法重新标记 Prometheus pod scrape label __address__
【发布时间】:2021-08-13 13:46:28
【问题描述】:

根据Prometheus documentation

"如果一个容器没有指定端口,则每个容器都有一个无端口目标 创建容器是为了通过重新标记手动添加端口。”

但是,在我的设置中,带有 containerports 的 pod 的 address 标签已按预期转换,但那些没有 containerports 的 pod 被保留为“无端口”。这是常见/可接受的行为,还是我应该改变一些东西才能将 __meta_kubernetes_pod_annotation_prometheus_io_port 作为地址端口?谢谢!

    additionalScrapeConfigs:
    - job_name: 'perpod-metricsscrape'
      scrape_interval: 5s
      metrics_path: /metrics
      kubernetes_sd_configs:
        - role: pod
      relabel_configs:
      - source_labels: [ __meta_kubernetes_pod_annotation_prometheus_io_scrape ]
        action: keep
        regex: true
      - 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
        regex: (.+)(?::\d+);(\d+)
        replacement: ${1}:${2}
        target_label: __address__
      - action: labelmap
        regex: __meta_kubernetes_pod_label_(.+)

顺便说一句,我从大多数漂浮的示例中稍微更改了正则表达式,认为它们与没有端口的地址不匹配(与前面提到的无容器 pod 的情况一样) - 在重新标记之前:_ _ 地址 _ ="1.2.3.4"

【问题讨论】:

    标签: kubernetes prometheus


    【解决方案1】:

    在正则表达式中发现问题,并替换... 我现在匹配无端口的_ _地址_ _,捕获可选端口,并替换为_ _ meta_kubernetes_pod_annotation_prometheus_io_port:

       regex: ([^:]+)(:\d+)?;(\d+)
       replacement: ${1}:${3}
    

    【讨论】:

      猜你喜欢
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      • 1970-01-01
      • 2020-07-24
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多