当前位置: 首页 > news >正文

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字段一样的指标聚合到一起。

http://www.lryc.cn/news/533668.html

相关文章:

  • 使用docker搭建FastDFS文件服务
  • 【R语言】数据分析
  • 蓝桥杯C语言组:图论问题
  • jmeter 性能测试Linux 常用的安装
  • 19 角度操作模块(angle.rs)
  • 前端高级面试题及其答案
  • 【ORACLE】这个‘‘和null不等价的场景,deepseek你怎么看?
  • 使用Python实现PDF与SVG相互转换
  • ComfyUI 安装教程:macOS 和 Linux 统一步骤
  • 360手机刷机 360手机解Bootloader 360手机ROOT
  • t113-qt
  • 【真一键部署脚本】——一键部署deepseek
  • 【AI 语音】实时语音交互优化全解析:从 RTC 技术到双讲处理
  • pytest-xdist 进行多进程并发测试
  • 【Android】版本和API对应关系表
  • 通过acme生成与续签ssl证书,并部署到nginx
  • mysql系统库介绍,数据字典(介绍,存储方式,常见表,访问权限),系统表(介绍,不同功能的表)
  • spring 学习(工厂方式 实例化对象(静态工厂,实例化工厂,实现factorybean 规范))
  • MarkupLM:用于视觉丰富文档理解的文本和标记语言预训练
  • 讯飞智作 AI 配音技术浅析(三):自然语言处理
  • kafka服务端之日志存储
  • 软件工程的熵减:AI如何降低系统复杂度
  • 模拟开发小鹅通首页网站练习
  • Ubuntu 下 nginx-1.24.0 源码分析 - ngx_strerror 函数
  • 第26场蓝桥入门赛
  • 【CAPL实战】实现弹窗提示及操作
  • 基于ESP32的远程开关灯控制(ESP32+舵机+Android+物联网云平台)
  • 协议-ACLLite-ffmpeg
  • ARM嵌入式学习--第十四天(SPI)
  • DeepSeek-V2 论文解读:混合专家架构的新突破