在 Spring Boot 2 指标中添加“平均值”、“最小值”或“百分位数”?

Posted

技术标签:

【中文标题】在 Spring Boot 2 指标中添加“平均值”、“最小值”或“百分位数”?【英文标题】:Adding 'mean', 'min' or 'percentiles' to Spring Boot 2 metrics? 【发布时间】:2018-08-16 09:39:50 【问题描述】:

我在 Spring Boot 2 版本 2.0.0-RELEASE 中使用新的 MicroMeter 指标。

通过/actuator/metrics/metric.name 端点发布指标时,我得到以下信息:

对于DistributionSummary

"name": "sources.ingestion.rate",
    "measurements": [
        
           "statistic": "COUNT",
            "value": 5
        ,
        
            "statistic": "TOTAL",
            "value": 72169.44162067816
        ,
        
            "statistic": "MAX",
            "value": 17870.68010661754
        
    ],
    "availableTags": []

对于Timer


    "name": "sources.ingestion",
    "measurements": [
        
            "statistic": "COUNT",
            "value": 5
        ,
        
            "statistic": "TOTAL_TIME",
            "value": 65.700878648
        ,
        
            "statistic": "MAX",
            "value": 22.661545322
        
    ],
    "availableTags": []

是否可以丰富度量以添加度量,例如 meanminpercentiles

对于百分位数,我尝试使用 .publishPercentiles(0.5, 0.95),但这并没有反映在执行器端点上。

【问题讨论】:

【参考方案1】:

在 Github 上讨论后,目前在 Micrometer 中没有实现。 有关 Github 问题的更多详细信息:

https://github.com/micrometer-metrics/micrometer/issues/488#issuecomment-373249656

https://github.com/spring-projects/spring-boot/issues/12433

https://github.com/micrometer-metrics/micrometer/issues/457

【讨论】:

【参考方案2】:

现在您可以像这样实现百分位直方图:

  metrics:
    distribution:
      percentiles-histogram:
        http.server.requests: true

然后你可以在/actuator/prometheus中看到直方图数据,但是在/metrics中看不到。因为它只会为支持直方图的端点生成。

【讨论】:

以上是关于在 Spring Boot 2 指标中添加“平均值”、“最小值”或“百分位数”?的主要内容,如果未能解决你的问题,请参考以下文章

不能在 Spring Boot 2(版本 2.0.0.M7)中包含 Prometheus 指标

无法将 Spring Boot 指标发布到 GCP 堆栈驱动程序

Spring Boot 默认指标从哪来?

Spring Boot 默认的指标数据从哪来的?

Spring Boot 2 Actuator 不发布 jvm 指标

Spring Boot 2 Actuator Starter 中的 Nullpointer w。 Tomcat指标