简体   繁体   English

如何从 spring-boot 千分尺检索指标

[英]How to retrieve metrics from spring-boot micrometer

I was experimenting with micrometer using below code.我正在使用以下代码试验千分尺。 How do i configure rate aggregation and get rate-aggregated data from a given counter within the application.我如何配置速率聚合并从应用程序中的给定计数器获取速率聚合数据。 By rate aggregated i mean data for previous publishing interval ?通过聚合率,我的意思是之前发布间隔的数据?

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());

Note: I dont want to publish metrics to any monitoring system.注意:我不想将指标发布到任何监控系统。 I would like to track number of requests given tags per interval (eg, successful/failure requests for a given interval) in application itself and use it for resilience purpose.我想跟踪应用程序本身中每个间隔给定标签的请求数(例如,给定间隔的成功/失败请求)并将其用于弹性目的。

Based on the comment from the author of the project, Micrometer intends to export metrics to an external product-ready monitoring system like Prometheus, so your approach is kind of unusual.根据项目作者的评论,Micrometer 打算将指标导出到像 Prometheus 这样的外部产品就绪监控系统,所以你的方法有点不寻常。

Micrometer supports rate-aggregation for monitoring systems which don't support rate-aggregation like InfluxDB and its support comes from StepMeterRegistry . Micrometer 支持监控系统的速率聚合,这些系统不支持像 InfluxDB 这样的速率聚合,它的支持来自StepMeterRegistry But SimpleMeterRegistry is not one of its subclasses, so you need to create your own one if you want to stick to the approach.但是SimpleMeterRegistry不是它的子类之一,所以如果你想坚持这种方法,你需要创建自己的一个。

UPDATED:更新:

I created a sample for a custom StepMeterRegistry .为自定义StepMeterRegistry创建了一个示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用千分尺指定我想要在spring-boot中使用的度量标准的白名单 - How to specify a whitelist of the metrics I want to use in spring-boot with micrometer Spring-boot micrometer timer() 它是如何工作的? - Spring-boot micrometer timer() how does it work? 如何将spring-boot指标保存为日志? - How to persist spring-boot metrics as log? 从 jar 获取千分尺指标到 spring 引导应用程序 - Getting micrometer metrics from a jar to a spring boot application 使用 spring java 的千分尺指标(没有 spring boot) - Micrometer metrics with spring java (NO spring boot) 如何用spring-boot显示Dropwizard Metrics Servlet? - How to show Dropwizard Metrics Servlet with spring-boot? 如何在不使用 Spring 或 Spring Boot 的情况下使用 Micrometer 在 TICK 堆栈上收集指标? - How to use Micrometer for metrics collection on TICK stack without using Spring or Spring Boot? 在弹簧引导中为石墨千分尺事件添加前缀 - Add prefix to graphite micrometer event in spring-boot Spring 启动 2.x 批处理应用程序,如何访问千分尺缓存指标以进行日志记录? - Spring Boot 2.x Batch application, how to access Micrometer cache metrics for logging? 如何从Dropwizard指标正确切换到千分尺? - How to switch correctly from Dropwizard metrics to Micrometer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM