【问题标题】:springboot micrometer how to collect method execution time,not max timespring boot千分尺如何收集方法执行时间,而不是最大时间
【发布时间】:2022-06-22 02:15:25
【问题描述】:

使用 Timer 作为 timer.record() ,得到如下结果

method_metrics_seconds_max{application="mydemo",class="com.demo.service.Impl.MetricsDemoService2Impl",method="getMethod1",} 0.21 method_metrics_seconds_count{application="mydemo",class="com.demo.service.Impl.MetricsDemoService2Impl",method="getMethod4",} 1.0 method_metrics_seconds_sum{application="mydemo",class="com.demo.service.Impl.MetricsDemoService2Impl",method="getMethod4",} 3.603

但我想得到真正的执行时间

找了很多资料都没找到

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。
  • real execution time 是什么意思?
  • 以@Michael McFadyen为例,一个方法funA,执行了3次,执行时间分别为200ms,240ms,180ms,我们可以从micrometer timer-max得到240ms,但不能得到每一次的次数

标签: timer spring-boot-actuator micrometer


【解决方案1】:

指标基本上是时间上的聚合数据点。我认为您要问的是原始数据(未汇总)。 即使指标库不会向您提供原始数据(因为它们正在聚合数据),您也有几个选择:

  1. 您可以使用Percentile histograms(推荐),以便查看例如介于 100 到 200 毫秒之间的请求数,您还可以在后端计算百分位数
  2. 你可以使用Client-side percentiles(不推荐)这样你就可以看到百分位数了
  3. 将数据推送到您的日志中(不推荐)
  4. 使用Spring Cloud Sleuth,这是我们的分布式跟踪解决方案,它可以记录单独的 HTTP 请求的持续时间
  5. 您可以使用 Micrometer 的新 Observation API 并随心所欲地记录数据(一旦发布,将推荐:2022 年底左右,Spring Boot 3 也将支持此功能)

【讨论】:

    猜你喜欢
    • 2020-02-17
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多