3

我想将 Micrometer 的 @Timed 注释中的数据捕获到 Prometheus 指标存储/注册表中。我在网上找不到任何关于如何做到这一点的解释。

这些是我正在使用的版本:

compile 'org.springframework.boot:spring-boot-starter-web:2.1.4.RELEASE' // This already includes micrometer I believe
compile "io.micrometer:micrometer-registry-prometheus:1.1.4'

我正在尝试计时存储库调用:

interface HouseRepository { 

@Timed
@Query(some long complicated query)
House deleteByAddressAndLastModifiedBefore(
    Address address,
    Instant instant
)

}

我该怎么做呢?我尝试在 @Timer 注释中添加一些不同的配置,例如:

  @Timed(description = 'this.is.my.metric', value = 'my.metric', extraTags = ['my.metric.name', 'test'])

但我在 Prometheus (/prometheus) 中看不到我的输出。

当然,这可能吗?

4

1 回答 1

11

根据千分尺文档

Micrometer 的 Spring Boot 配置无法识别任意方法上的 @Timed。

要使@Timed注解按您希望的方式工作,您可能需要配置一个TimedAspectbean。

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

应用TimedAspect可以@Timed用于任何任意方法。

于 2019-06-10T23:38:22.070 回答