春季指标中的@Timed注释 [英] @Timed annotation in spring metrics

查看:95
本文介绍了春季指标中的@Timed注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在String Boot rest控制器上使用了 @Timed 批注,并且工作正常.控制器中的方法从服务中调用方法,该方法也用 @Timed 注释.

I use @Timed annotation on String Boot rest controller and it works fine. Method from controller calls method from service which is also annotated with @Timed.

但是,此后续Service Bean中方法的注释不起作用(在/metrics 中看不到结果).为什么会这样呢?可以解决吗?

However, this annotation on method in subsequent service bean doesn't work (I don't see results in /metrics). Why is it happening? Could it be fixed?

推荐答案

根据@Timed在任何Spring管理的bean#361 中,您可以通过注册

As per Support for @Timed in any Spring-managed bean #361 you can get this behaviour by registering TimedAspect manually.

@Configuration
@EnableAspectJAutoProxy
public class AutoTimingConfiguration {
  @Bean
  public TimedAspect timedAspect(MeterRegistry registry) {
    return new TimedAspect(registry);
  }
}

请注意,按照#361中的jkschneider注释:

Do note that as per jkschneider comment in #361:

根据社区对此功能的反应,我们可以通过Boot 2.1中的AOP或BPP重新访问@Timed的应用程序.

We can revisit application of @Timed via AOP or a BPP in Boot 2.1, depending on how the community reacts to the feature.

这篇关于春季指标中的@Timed注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆