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

相关推荐
chen_note20 小时前
监控——普罗米修斯
grafana·prometheus
闲人编程21 小时前
Prometheus监控指标集成指南
prometheus·监控·promql·仪表盘··cncf·codecapsule
木子欢儿2 天前
Prometheus Blackbox域名SSL证书监控并设置AlertManager告警
网络·网络协议·ssl·prometheus
wxjlkh3 天前
docker 搭建 grafana+prometheus 监控主机资源之node_exporter
docker·grafana·prometheus
yunson_Liu3 天前
kube-prometheus-stack基础上部署domain-exporter监控域名注册过期时间
prometheus
是垚不是土4 天前
基于Blackbox Exporter的网络服务黑盒监控体系实践
网络·数据库·安全·http·微服务·prometheus
阿拉斯攀登4 天前
SkyWalking 与 Zipkin、Prometheus 深度对比分析
prometheus·skywalking·可观测性·zipkin
星哥说事5 天前
Zabbix与Prometheus在服务器及网络设备管理中的应用
服务器·zabbix·prometheus
cui_win6 天前
Prometheus实战教程 - mysql监控
mysql·prometheus·压测
nVisual6 天前
Prometheus连接nVisual实现资产拓扑业务关联分析
prometheus