简体   繁体   English

Spring Boot 1.x,如何将指标增加一定数量

[英]Spring boot 1.x , How to increment a metric by an amount

I have an application built with spring boot 1.x and the whole process to expose metric is different from v2.x of spring boot. 我有一个使用Spring Boot 1.x构建的应用程序,公开指标的整个过程与Spring Boot v2.x不同。

Currently, I am using a cache in my application where i check for key existence in bulk and my requirement is that the counterService that increments a metric should increment it by some amount rather than by 1 so that I can leverage the bulk part atleast. 当前,我在应用程序中使用高速缓存,在该应用程序中我检查批量是否存在键,而我的要求是,增加指标的counterService应将其递增一定数量而不是1,以便我可以至少利用批量部分。

How do i achieve that? 我该如何实现?

One way i have done before is including Dropwizard metrics in spring boot. 我之前做过的一种方法是在春季启动中加入Dropwizard指标。 But I want to work under the scope of Spring boot actuators. 但是我想在Spring Boot执行器的范围内工作。

You may just have to implement your own CounterService using the DefaultCounterService as a template: https://github.com/spring-projects/spring-boot/blob/v1.5.17.RELEASE/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterService.java 您可能只需要使用DefaultCounterService作为模板来实现自己的CounterServicehttps : //github.com/spring-projects/spring-boot/blob/v1.5.17.RELEASE/spring-boot-actuator/src/main/的Java /组织/ springframework的的/ boot /开动/度/编剧/ DefaultCounterService.java

Then add methods something to the tune of increment(String metricName, int delta) . 然后添加一些方法来达到increment(String metricName, int delta)

Then register an instance of the bean in your configuration - and it'll override the DefaultCounterService . 然后在您的配置中注册Bean的实例-它将覆盖DefaultCounterService

You'll need to refer to the instance by your specific type name so you can access the methods you added. 您需要通过特定的类型名称来引用实例,以便可以访问添加的方法。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM