【问题标题】:Metrics http_server_requests_seconds_count in spring boot application using cxf-spring-boot-starter-jaxrs contains uri as "UNKNOWN"使用 cxf-spring-boot-starter-jaxrs 的 Spring Boot 应用程序中的指标 http_server_requests_seconds_count 包含 uri 作为“未知”
【发布时间】:2019-08-26 07:11:50
【问题描述】:

2.0.8 版 Spring Boot 应用程序中的指标 http_server_requests_seconds_count。使用 spring actuator 公开的Release 包含以下 URI:

“未知”。

Spring Boot 应用程序正在使用 cxf-spring-boot-starter-jaxrs 来暴露其余端点。 我在我的项目中添加了micrometer-registry-prometheus 依赖项。

http_server_requests_seconds_count{exception="None",method="POST",status="200",uri="UNKNOWN",} 2.0

我尝试在我的项目中添加 micrometer-jersey2 依赖项。

实际

http_server_requests_seconds_count{exception="None",method="POST",status="200",uri="UNKNOWN",} 2.0

预期:

http_server_requests_seconds_count{exception="None",method="GET",status="200",uri="/sayHello",} 2.0

【问题讨论】:

  • Apache CXF 不是另一个/替代 JAX-RS 实现吗?micrometer-jersey2 明确地只支持 Jersey JAX-RS 实现。
  • 是的,Apache CXF 是 JAX-RS 的替代实现。千分尺只提供球衣模块,CXF没有这个模块。

标签: spring spring-boot metrics spring-boot-actuator spring-micrometer


【解决方案1】:

在 OP cmets 中澄清后(CXF 是另一个 JAX-RS 实现):Micrometer 目前不支持处理 CXF 请求。它(Spring WebMvc)无法提取可选参数化的请求 url,在这种情况下会退回到 UNKNOWN。 (否则,如果您的 CXF 端点提供一些高度可参数化的 URL,从而获得大量流量,这可能会导致指标爆炸。)

因此,您可以查看micrometer-jersey2 实现并派生micrometer-cxf 实现;)(或者,如果还没有这种情况(使用搜索)-打开 Micrometer 或 CXF 项目的问题。我是提到后者,因为他们可能有兴趣处理该实现。)

【讨论】:

    【解决方案2】:

    您还可以使用 io.github.ddk-prog:cxf-prometheus-metrics 为 prometheus 收集 cxf 指标。

    为你的 pom.xml 添加依赖

    <dependency>
        <groupId>io.github.ddk-prog</groupId>
        <artifactId>cxf-prometheus-metrics</artifactId>
        <version>1.0.0</version>
    </dependency>
    

    以及以下 bean 到您的应用程序配置。

    @Bean
    public FactoryBeanListener cxfPrometheusFeatureBean(final CollectorRegistry registry) {
        return new PrometheusFactoryBeanListener(registry);
    }
    

    您将在 Spring Boot 执行器 prometheus 报告中获得每个端点和操作的 cxf_requests_total、cxf_requests_success、cxf_requests_failed、cxf_requests_seconds。 例如,

    cxf_requests_seconds{endpoint="server1",operation="server1Method",} 0.0157349
    

    【讨论】:

      【解决方案3】:

      如果需要千分尺报告的cxf统计,可以试试

      <dependency>
          <groupId>io.github.kdprog</groupId>
          <artifactId>cxf-micrometer-metrics</artifactId>
          <version>1.0.0</version>
      </dependency>
      

      将报告以下统计数据

      cxf_requests_processed_total - total number of cxf requests ,
      cxf_requests_seconds_sum     - total execution time of cxf requests,
      cxf_requests_seconds_max     - maximum execution time of cxf request,
      cxf_requests_success_total   - total number of successfully processed cxf requests,
      cxf_requests_failed_total    - total number of failed cxf requests
      

      对于每个客户端或服务器 cxf 端点的每个 Web 服务方法。

      对于 Spring 应用程序,将以下 bean 添加到您的应用程序配置中。

      @Bean
      public FactoryBeanListener cxfMicrometerBean(final MeterRegistry registry) {
          return new MicrometerFactoryBeanListener(registry);
      }
      

      【讨论】:

        【解决方案4】:

        https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator.metrics.supported

        您可以制作自定义标签提供程序来覆盖它:

        @Bean
        WebMvcTagsProvider webMvcTagsProvider() {
            return new DefaultWebMvcTagsProvider() {
                @Override
                public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response,
                                             Object handler, Throwable exception) {
                    return Tags.concat(
                            super.getTags(request, response, handler, exception),
                            Tags.of(Tag.of("uri",request.getRequestURI()))
                    );
                }
            };
        }
        

        More examples.

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-05-23
          • 1970-01-01
          • 2020-11-06
          • 2021-06-01
          • 2014-04-07
          • 1970-01-01
          相关资源
          最近更新 更多