How to filter out Web Client metrics by client name in SpringBoot actuator?

758 views Asked by At

For my use case I need management.metrics.web.client.request.autotime.enabled: true. However there is one client name I need filter out from these metrics. For example, everything except metrics below should be allowed. Here, the differentiating factor is the clientName

  • http_client_requests_seconds_count{clientName="someClientName",method="GET",outcome="CLIENT_ERROR",status="404",uri="client.com",} 1.0
  • http_client_requests_seconds_sum{clientName="someClientName",method="GET",outcome="SUCCESS",status="200",uri="client.com",} 1.0

Is this possible?

1

There are 1 answers

0
Hans-Christian On

It is possible with the a meter filter which gives the possibility to deny or accept a specific metric based on the tags.

Simple example how to use in a Spring Boot @Configuration class:

@Bean 
public MeterRegistryCustomizer<MeterRegistry> metricsRegistryConfig() {
  return registry -> registry.config()
      .meterFilter(MeterFilter.deny(id -> {
        var clientName = id.getTag("clientName");
        return clientName != null && "someClientName".equals(clientName);
      }));
}

This will deny all metrics using the given tag. It is also possible to further refine the filter using the meter name, e.g if (id.getName().startsWith("http.client.requests"))