You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.1.4中WebClient指标未暴露的问题求助

解决WebClient指标未显示的问题

针对你遇到的WebClient的http.client.requests指标未在Actuator端点中出现的问题,可按以下步骤排查解决:

1. 确保WebClient使用Spring管理的Builder实例

手动通过WebClient.builder()创建的实例不会自动集成Micrometer的指标拦截器,需要改用Spring容器注入的WebClient.Builder来构建:

// 注入Spring自动配置的WebClient.Builder
@Autowired
private WebClient.Builder webClientBuilder;

public WebClient createWebClient(String endpoint, String apiKey) {
    return webClientBuilder
            .baseUrl(endpoint)
            .defaultHeader("api-key", apiKey)
            .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
            .build();
}

Spring Boot的自动配置会为这个Builder添加Micrometer的指标采集拦截器,确保请求指标被记录。

2. 显式启用HTTP客户端指标(可选但稳妥)

虽然默认开启,可显式配置确保指标采集功能生效:

management:
  metrics:
    enable:
      http:
        client:
          requests: true

3. 触发实际请求后再检查指标

指标只有在WebClient发起真实请求后才会生成,先调用一次你的WebClient接口,再访问对应端点查看指标。

4. 确认端点访问路径正确

根据你的Actuator配置:

  • 原prometheus端点被映射为/metrics,这里会包含所有Prometheus格式的指标,可检查是否有http_client_requests_*前缀的指标
  • 原metrics端点被映射为/metrics-info,这里展示的是指标元数据而非具体数值

内容的提问来源于stack exchange,提问作者Prashant Aghara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 07:52:10