有没有办法将 Micrometer @Timed 注释捕获到 Prometheus 指标存储/注册表中?

G L*_*Lor 3 spring metrics prometheus micrometer spring-micrometer

我想将 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'
Run Code Online (Sandbox Code Playgroud)

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

interface HouseRepository { 

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

}
Run Code Online (Sandbox Code Playgroud)

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

  @Timed(description = 'this.is.my.metric', value = 'my.metric', extraTags = ['my.metric.name', 'test'])
Run Code Online (Sandbox Code Playgroud)

但是我在 Prometheus (/prometheus) 中没有看到我的输出。

当然,这是可能的吗?

jol*_*olo 10

根据千分尺文档

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

为了使@Timed注解能够如您所愿地工作,您可能需要配置一个TimedAspectbean。

@Configuration
public class TimedConfiguration {
   @Bean
   public TimedAspect timedAspect(MeterRegistry registry) {
      return new TimedAspect(registry);
   }
}
Run Code Online (Sandbox Code Playgroud)

ApplyingTimedAspect@Timed用于任何任意方法。


归档时间:

查看次数:

6839 次

最近记录:

6 年,7 月 前