pushgateway指标聚合问题

一 问题现象

一个job有多个实例推送指标,但是从pushgateway上看这个job的instance字段,只显示一个实例的ip,而不是多个实例。导致在grafana上无法正常根据ip查看监控。

应用的prometheus的配置

yaml 复制代码
management:
  metrics:
    tags:
      application: ${spring.application.name}
    export:
      prometheus:
        pushgateway:
          #pushgateway地址
          baseUrl:  ***:9091
          #推送周期
          pushRate: 15s
          #job定义名
          job: ${spring.application.name}
          #启用推送
          enabled: true
  ## actuator暴露出prometheus
  endpoints:
    web:
      exposure:
        include: prometheus
  endpoint:
    health:
      show-details: always

二 解决办法

增加grouping-key,避免多个不同的实例的指标被聚合。HOSTNAME这个环境变量是k8s自带的

yaml 复制代码
management:
  metrics:
    tags:
      application: ${spring.application.name}
    export:
      prometheus:
        pushgateway:
          #pushgateway地址
          baseUrl: ***:9091
          #推送周期
          pushRate: 15s
          #job定义名
          job: ${spring.application.name}
          #启用推送
          enabled: true
          grouping-key:
            hostname: ${HOSTNAME}
  ## actuator暴露出prometheus
  endpoints:
    web:
      exposure:
        include: prometheus,health
  endpoint:
    health:
      show-details: always

三 groupingkey作用分析

pushgateway指标上报的源码路径:io.prometheus.client.exporter.PushGateway#doRequest

没配置groupingkey的时候
配置了groupingkey的时候

由于是本机debug,HostName这个环境变量取不到,k8s上正常。

grouping-key 官方解释 https://github.com/prometheus/pushgateway

The default port the Pushgateway is listening to is 9091. The path looks like

      /metrics/job/<JOB_NAME>{/<LABEL_NAME>/<LABEL_VALUE>}

<JOB_NAME> is used as the value of the job label, followed by any number of other label pairs (which might or might not include an instance label). The label set defined by the URL path is used as a grouping key. Any of those labels already set in the body of the request (as regular labels, e.g. name{job="foo"} 42) will be overwritten to match the labels defined by the URL path!

pushgateway是用请求pushgateway的url的path作为grouping-key的。如果不配置任何grouping-key,pushgateway会把所有job一样的指标聚合到一起

相关推荐
liuyicenysabel9 小时前
Grafana + Prometheus 分级告警配置设计(P0/P1/P2)
javascript·grafana·prometheus
随遇而安zx9 小时前
SpringCloud---可观测性与监控:Actuator / Micrometer / Prometheus / Grafana 深度解析
spring cloud·grafana·prometheus
qq_4523962311 小时前
第四篇:《Prometheus 深度实战:指标设计、Exporter 开发与服务发现》
服务发现·prometheus
刘某的Cloud13 小时前
k8s部署prometheus架构规则
linux·运维·kubernetes·prometheus·监控
LlmCraft|大模型工程实践15 小时前
12. Docker 日志管理与监控:ELK 日志收集 + Prometheus 性能监控
elk·docker·prometheus
DevOps老兵1 天前
AI Infra实战02:GPU监控实战,用DCGM+Prometheus+Grafana看清每一张卡
人工智能·grafana·prometheus·ai infra·gpu监控·dcgm
heimeiyingwang1 天前
【Prometheus·入门篇】数据模型:Metric 类型、标签与时间序列
prometheus
heimeiyingwang1 天前
【Prometheus·部署篇】配置详解:scrape_config、relabeling 与服务发现
prometheus
heimeiyingwang5 天前
【Prometheus·入门篇】Prometheus 是什么:从 Nagios 到云原生监控的演进
prometheus
秋风点枝6 天前
第一篇:认识 Prometheus —— 云原生监控的基础
云原生·prometheus