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

相关推荐
JAVA拾贝13 小时前
Prometheus+Grafana运维监控并实现钉钉告警
运维·钉钉·grafana·prometheus·运维监控
TDengine (老段)13 天前
使用 Prometheus 访问 TDengine ---
大数据·数据库·prometheus·时序数据库·iot·tdengine·涛思数据
枫桥听月13 天前
16.大数据监控
大数据·prometheus
广目软件14 天前
GM DC Monitor v2.0 卸载教程
服务器·网络·zabbix·prometheus
不太聪明的样子15 天前
c++ 项目使用 prometheus + grafana 进行实时监控
c++·grafana·prometheus
南夏一木子20 天前
性能测试——搭建Prometheus+Grafana平台
grafana·prometheus
奈斯ing21 天前
【prometheus+Grafana篇】基于Prometheus+Grafana实现postgreSQL数据库的监控与可视化
运维·数据库·信息可视化·grafana·prometheus
xixingzhe222 天前
docker compose安装Prometheus、Grafana
docker·grafana·prometheus
碧水澜庭23 天前
Prometheus+ Grafana 监控系统入门
grafana·prometheus
遇见火星23 天前
一键部署Prometheus+Grafana+alertmanager对网站状态进行监控
grafana·prometheus