How to expose outbound metrics for prometheus for the webclient requests?

2.3k Views Asked by At

Hi I am quite new to prometheus metrics. I need to expose the http_client_requests_seconds_count and http_client_requests_seconds_sum for the requests to the down stream servers.

I have enabled the prometheus in my project by

management:
  endpoints:
    web:
      exposure:
        include: health,metrics,prometheus

I have added dependencies as below in my pom.xml

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
  <version>${micrometer.version}</version>
</dependency>

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

and I can see the inbound matrix in http://localhost:8092/actuator/prometheus. Like http_server_requests_seconds and others but unable to find the downstream metrics.

I am using spring web-flux reactive framework.

1

There are 1 best solutions below

1
On BEST ANSWER

As per this answer: stackoverflow.com/a/58632953 I tried it and found no luck. The simple answer is just to add AutoWired to WeclientBuilder and build your Webclient out of it.

@Autowired
private WebClient.Builder webClientBuilder;

this.webClientBuilder.baseUrl(host)
        .clientConnector(clientHttpConnector)
        .build()
        .post()
        .uri(uri)...

Configure the metrics name in application.yml like below:

management:
  metrics:
    web:
      client:
        request:
          autotime:
            enabled: true
          metric-name: Any_Prefix_http_client_requests
      server:
        request:
          autotime:
            enabled: true
          metric-name: Any_Prefix_http_server_requests

That's it, you will get outbound metrics in /atuator/prometheus....

Thanks! Happy coding