2

I am trying to enable Prometheus endpoint in my springboot project having below dependencies.

SpringBoot version:

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.12-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

Dependencies:

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

I am using restTemplate to make outbound call but when i check Prometheus endpoint, the data related with http_client_requests_* are missing

Application properties:

management.endpoints.web.exposure.include=health,metrics,prometheus
management.endpoint.health.show-details=always
management.endpoint.health.enabled=true
management.endpoint.info.enabled=true
management.metrics.web.server.request.autotime.percentiles=0.90,0.95
management.metrics.web.client.request.autotime.percentiles=0.90,0.95
management.metrics.web.client.request.autotime.enabled=true
dead programmer
  • 4,223
  • 9
  • 46
  • 77
  • I also used `RestTemplate` for outbound call and I didn't see `http.client.requests` when I visited `/actuator/metrics`. – LHCHIN Oct 04 '22 at 01:51
  • Have you constructed your RestTemplate manually or as a spring bean? You need to make sure that you allow micrometer a chance to instrument the requests. you can use RestTemplateBuilder if you need to add your own customisation. Also you may need to add io.micrometer:micrometer-core dependency. This set up works for me. – waltron Nov 09 '22 at 08:19

1 Answers1

3

Just ensure you create your RestTemplate as a spring managed bean to ensure it gets a chance for instrumentation (if not auto created). You can customise with RestTemplateBuilder, and then inject it into the place you need like any other Spring bean.

@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
    return restTemplateBuilder.additionalCustomizers(myRestTemplateCustomizer())
            .build();

}

And you may also require

<!-- Micrometer core dependency  -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
</dependency>

Manual creation (using 'new' within a class) is one cause for it to not link up to metrics.

waltron
  • 131
  • 9