我正在尝试 Javax/JaxRs,并且使用的是 WildFly 25 服务器,我对此不太熟悉。
在搜索类似于 Spring 的 Actuator 的东西时,我偶然发现了服务器默认公开的指标和运行状况端点,以及它向应用程序端点添加自定义计数器、仪表等的能力。
然而,无论我做什么,这些自定义端点不会在默认的 http://localhost:9990/metrics URL 下公开。
我按照 GitHub 存储库下 WildFly 提供的指南进行操作:https://github.com/wildfly/quickstart/tree/main/microprofile-metrics https://github.com/wildfly/quickstart/tree/main/microprofile-metrics
教程上有一些“危险信号”,似乎与我尝试做的任何事情都不起作用。
- 该指南建议,如果我们想要获取 JSON 格式的指标,我们需要使用以下标头:“
Accepted: application/json
”,它仍然返回默认的 Prometheus 格式,在 Postman 和 Curl 中都是如此。
- 该指南还建议指标/供应商, 指标/应用, 指标/基础返回不同范围的指标,根据我的测试,它们都返回相同的。
就教程代码而言,我尝试在 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
I am using IntelliJ, so I tried doing the same from within the IDE:
(“启用统计”选项已添加到虚拟机选项和启动期间的蝙蝠上,以确保其正常工作)
以下是我正在使用的依赖项(基于我的服务器版本):
<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>