How to publish @Timed metrics right after the application startup

29 Views Asked by At

Application use Spring Boot 3 (3.2.1).
Application publish Prometheus metrics using Micrometer.
Here is part of pom.xml configuration:

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
  <scope>runtime</scope>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

I use @Timed (io.micrometer.core.annotation.Timed) annotation to publish metrics.
Example:

@Timed(value = "get_all_books", percentiles = 0.95)
public List<Book> getAll() {
  return booksStorage.getAll();
}

It's work well but I could see this metrics just after the method will be called at least once.

How can I configure to see these metrics right after the application startup? I mean I want to see these metrics in the GET /actuator/prometheus response even if the methods are not called at all. I understand that the values of the metrics will be zeros, but our support team wants to see them anyway.

0

There are 0 best solutions below