我想将 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’s Spring Boot configuration does not recognize @Timed on arbitrary methods.
要使 @Timed
注释按您希望的方式工作,您可能需要配置一个 TimedAspect
bean。
@Configuration
public class TimedConfiguration {
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}
Applying
TimedAspect
makes@Timed
usable on any arbitrary method.
关于spring - 有没有办法将 Micrometer @Timed 注释捕获到 Prometheus 指标存储/注册表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56533986/