我想从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)中看不到我的输出。

当然可以吗?

最佳答案

根据micrometer docs


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


为了使@Timed注释能够按您希望的方式工作,您可能需要配置TimedAspect bean。

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



应用TimedAspect使@Timed在任何任意方法上均可使用。

10-08 20:14