欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > pushgateway指标聚合问题

pushgateway指标聚合问题

2025/6/8 15:05:04 来源:https://blog.csdn.net/bruce128/article/details/140839730  浏览:    关键词:pushgateway指标聚合问题

一 问题现象

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

在这里插入图片描述
应用的prometheus的配置

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

二 解决办法

增加grouping-key,避免多个不同的实例的指标被聚合。HOSTNAME这个环境变量是k8s自带的,并且每个实例都不一样。当时想找一个能标识pod ip的环境变量,用env命令搜了一下,并没有。

management:metrics:tags:application: ${spring.application.name}export:prometheus:pushgateway:#pushgateway地址baseUrl: ***:9091#推送周期pushRate: 15s#job定义名job: ${spring.application.name}#启用推送enabled: truegrouping-key:hostname: ${HOSTNAME}## actuator暴露出prometheusendpoints:web:exposure:include: prometheus,healthendpoint: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字段一样的指标聚合到一起。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词