4.2. 指标功能
使用 Micrometer 收集指标。
与 CXF Metrics 功能 不同,这个 Quarkus CXF 扩展不支持 Dropwizard Metrics。仅支持 Micrometer。
4.2.1. Maven 协调 复制链接链接已复制到粘贴板!
在 code.quarkus.redhat.com 上使用 quarkus-cxf-rt-features-metrics 创建新项目,或将这些协调添加到现有项目中:
<dependency>
<groupId>io.quarkiverse.cxf</groupId>
<artifactId>quarkus-cxf-rt-features-metrics</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.cxf</groupId>
<artifactId>quarkus-cxf-rt-features-metrics</artifactId>
</dependency>
4.2.2. 使用方法 复制链接链接已复制到粘贴板!
CXF 集成到 Quarkus Micrometer 生态系统中的集成是使用 io.quarkiverse.cxf.metrics.QuarkusCxfMetricsFeature 实施的。只要您的应用程序依赖于 quarkus-cxf-rt-features-metrics,在内部为 Quarkus CXF 创建并默认启用 QuarkusCxfMetricsFeature 实例。您可以通过 quarkus.cxf.metrics.enabled-for,quarkus.cxf.client."client-name".metrics.enabled 和 quarkus.cxf.endpoint."/endpoint-path".metrics.enabled 属性禁用它。
4.2.2.1. runnable 示例 复制链接链接已复制到粘贴板!
在 Quarkus CXF 源树中有一个涵盖 Micrometer Metrics 的集成测试。https://github.com/quarkiverse/quarkus-cxf/tree/main/integration-tests/metrics
不正常,它依赖于 quarkus-cxf-rt-features-metrics
pom.xml
<dependency>
<groupId>io.quarkiverse.cxf</groupId>
<artifactId>quarkus-cxf-rt-features-metrics</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.cxf</groupId>
<artifactId>quarkus-cxf-rt-features-metrics</artifactId>
</dependency>
它使用 quarkus-micrometer-registry-prometheus 扩展来导出 JSON 格式和 Prometheus 的指标:
pom.xml
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
</dependency>
需要以下配置才能检查通过 REST 端点收集的指标:
application.properties
quarkus.micrometer.export.json.enabled = true quarkus.micrometer.export.json.path = metrics/json quarkus.micrometer.export.prometheus.path = metrics/prometheus
quarkus.micrometer.export.json.enabled = true
quarkus.micrometer.export.json.path = metrics/json
quarkus.micrometer.export.prometheus.path = metrics/prometheus
使用以上所有设置,您可以在 Dev 模式中启动应用程序:
mvn quarkus:dev
$ mvn quarkus:dev
现在,向 HelloService 发送请求:
curl \ -d '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:helloResponse xmlns:ns2="http://it.server.metrics.cxf.quarkiverse.io/"><return>Hello Joe!</return></ns2:helloResponse></soap:Body></soap:Envelope>' \ -H 'Content-Type: text/xml' \ -X POST \ http://localhost:8080/metrics/client/hello
$ curl \
-d '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:helloResponse xmlns:ns2="http://it.server.metrics.cxf.quarkiverse.io/"><return>Hello Joe!</return></ns2:helloResponse></soap:Body></soap:Envelope>' \
-H 'Content-Type: text/xml' \
-X POST \
http://localhost:8080/metrics/client/hello
之后,您应该在上述配置的端点的输出中看到 cxf.server.requests 下的一些指标:
4.2.3. 配置 复制链接链接已复制到粘贴板!
在构建时修复的配置属性。所有其他配置属性可在运行时覆盖。
| 配置属性 | 类型 | default |
|---|---|---|
|
|
| |
|
指定是否为客户端、服务(包括 或 none)启用指标集合。此全局设置可以分别使用
环境变量: | ||
|
| ||
|
对
环境变量: | ||
|
|
| |
|
如果为
环境变量: | ||
|
|
| |
|
如果为
环境变量: | ||