0

http_server_requests_seconds_count使用 spring 执行器公开的 Spring Boot 应用程序中的 2.0.8 版本的指标包含 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

4

4 回答 4

1

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

所以你可以看看micrometer-jersey2实现并派生一个micrometer-cxf实现;)(或者如果还没有的话(使用搜索)-打开千分尺或CXF项目的问题。我提到后者,因为他们可能会感兴趣负责该实施。)

于 2019-04-05T15:24:17.020 回答
0

您还可以使用 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 执行器普罗米修斯报告中获得每个端点和操作的 cxf_requests_total、cxf_requests_success、cxf_requests_failed、cxf_requests_seconds。例如,

cxf_requests_seconds{endpoint="server1",operation="server1Method",} 0.0157349
于 2020-04-25T07:16:21.250 回答
0

如果您需要千分尺报告的 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);
}
于 2020-05-10T12:26:49.570 回答
0

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()))
            );
        }
    };
}

更多示例。

于 2021-12-18T23:25:36.867 回答