[英]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.