简体   繁体   English

如何在 SpringBoot 执行器中按客户端名称过滤 Web 客户端指标?

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

For my use case I need management.metrics.web.client.request.autotime.enabled: true .对于我的用例,我需要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在这里,区别因素是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?这可能吗?

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:如何在 Spring Boot @Configuration类中使用的简单示例:

@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, eg if (id.getName().startsWith("http.client.requests"))也可以使用仪表名称进一步细化过滤器,例如if (id.getName().startsWith("http.client.requests"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM