【问题标题】:How to retrieve metrics from spring-boot micrometer如何从 spring-boot 千分尺中检索指标
【发布时间】:2019-02-22 08:59:15
【问题描述】:

我正在使用下面的代码试验千分尺。如何配置速率聚合并从应用程序中的给定计数器获取速率聚合数据。通过速率聚合我的意思是以前发布间隔的数据?

final MeterRegistry myRegistry = new SimpleMeterRegistry();
final Random random = new Random();
for (iteration = 0; iteration < 1000; iteration++)
{
    final int randomNum = random.nextInt(10);
    final Counter myCounter = myRegistry.counter("myTestCounter", "random", Integer.toString(randomNum));
    myCounter.increment();
    Thread.sleep(100);
}
System.out.println("measure = [" + myRegistry.counter("myTestCounter", "random", "0").measure());
System.out.println("count = [" + myRegistry.counter("myTestCounter", "random", "0").count());

注意:我不想将指标发布到任何监控系统。我想跟踪应用程序本身中每个间隔给定标签的请求数(例如,给定间隔的成功/失败请求)并将其用于弹性目的。

【问题讨论】:

    标签: java spring-boot micrometer spring-micrometer


    【解决方案1】:

    根据项目作者的评论,Micrometer 打算将指标导出到像 Prometheus 这样的外部产品就绪监控系统,所以你的方法有点不寻常。

    Micrometer 支持对不支持速率聚合的监控系统(如 InfluxDB)进行速率聚合,其支持来自 StepMeterRegistry。但是SimpleMeterRegistry 不是它的子类之一,因此如果您想坚持这种方法,则需要创建自己的子类。

    更新:

    我创建了a sample for a custom StepMeterRegistry

    【讨论】:

    • 谢谢@johhny-lim。题外话 - 你知道是否有满足我要求的库吗?
    • @joshu 创建自己的StepMeterRegistry 并不难。我更新了我的答案,为其添加了一个示例。
    猜你喜欢
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 2020-03-15
    • 2021-02-28
    • 2022-06-22
    • 2022-11-10
    • 2023-03-23
    • 2020-01-07
    相关资源
    最近更新 更多