1

Have written a springboot application, and wanted to measure the time taken to execute a method using @Timed annotation from micrometer, and display this value in prometheus.

Have tried below configuration, however the execution time is not displayed in prometheus:

Dependencies added for pom.xml

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
        <scope>runtime</scope>
    </dependency> 

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
    </dependency>

config for method :

@Timed(value = "testing.executiontime", longTask = true)
 testMethod(){}

TimedConfiguration.class

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

in application.yml

management:
  endpoints:
    web:
      exposure:
        include:
          - info
          - health
          - prometheus
          - metrics

prometheus.yml

global:
  scrape_interval:     15s

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:8080']

  - job_name: 'spring-actuator'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
Amulya M
  • 149
  • 1
  • 12

0 Answers0