【发布时间】:2021-11-27 10:34:01
【问题描述】:
我正在试验 Javax/JaxRs,我正在使用 WildFly 25 服务器,我不太熟悉。
在搜索类似于 Spring 的 Actuator 的东西时,我偶然发现了服务器默认公开的指标和健康端点,以及它向应用程序端点添加自定义计数器、仪表等的能力。
但是,无论我做什么,这些自定义端点都不会暴露在默认的 http://localhost:9990/metrics URL 下。
我正在遵循 GitHub 存储库下 WildFly 提供的指南: https://github.com/wildfly/quickstart/tree/main/microprofile-metrics
教程中有一些“危险信号”似乎不适用于我尝试做的任何事情。
- 该指南建议,如果我们想要获取 JSON 格式的指标,我们需要使用以下标头:“
Accepted: application/json”,它仍然返回默认的 Prometheus 格式,无论是 Postman 还是 Curl。 - 该指南还建议 metrics/vendor、metrics/application、metrics/base 返回不同范围的指标,我对此进行了测试,它们都返回相同的值。
就教程代码而言,我尝试在 Jakarta EE 8 Full & Web Distribution 上运行它,但它会引发以下错误:
Artifact microprofile-metrics:war exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"microprofile-metrics.war\".undertow-deployment" => "java.lang.NoClassDefFoundError: org/eclipse/microprofile/metrics/Counter Caused by: java.lang.NoClassDefFoundError: org/eclipse/microprofile/metrics/Counter
我尝试使用不同版本的 Java(1.8、11、17)编译代码,希望它可以解决问题,但无济于事。
但是,使用 WildFly Preview EE 9.1 Distribution 似乎停止抛出错误,但自定义指标仍然不起作用。
我在尝试期间添加到两个发行版中的子系统(取自standalone.xml):
<extension module="org.wildfly.extension.health"/>
<extension module="org.wildfly.extension.metrics"/>
<extension module="org.wildfly.extension.microprofile.config-smallrye"/>
<extension module="org.wildfly.extension.microprofile.fault-tolerance-smallrye"/>
<extension module="org.wildfly.extension.microprofile.health-smallrye"/>
<extension module="org.wildfly.extension.microprofile.jwt-smallrye"/>
<extension module="org.wildfly.extension.microprofile.metrics-smallrye"/>
<extension module="org.wildfly.extension.microprofile.openapi-smallrye"/>
<extension module="org.wildfly.extension.microprofile.opentracing-smallrye"/>
<extension module="org.wildfly.extension.undertow"/>
(其他为简洁省略)
我还尝试通过创建以下 bat 并启动它来启用统计信息:
call standalone.bat -Dwildfly.statistics-enabled=true
我正在使用 IntelliJ,所以我尝试在 IDE 中执行相同的操作:
(“启用统计”选项已添加到 VM 选项和启动期间的 bat 中以确保其正常工作)
以下是我使用的依赖项,基于我的服务器版本:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-microprofile</artifactId>
<version>25.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-jakartaee8-with-tools</artifactId>
<version>25.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Import the MicroProfile Metrics API, we use provided scope as the API is included in the server -->
<dependency>
<groupId>org.eclipse.microprofile.metrics</groupId>
<artifactId>microprofile-metrics-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the CDI API, we use provided scope as the API is included in the server -->
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Jakarta REST API, we use provided scope as the API is included in the server -->
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
【问题讨论】:
标签: java jax-rs wildfly microprofile