简体   繁体   English

MicroProfile 指标不会在 Wildfly 25 上显示自定义指标

[英]MicroProfile Metrics do not show custom metrics on Wildfly 25

I am experimenting with Javax/JaxRs and I am using the WildFly 25 server, which I am not quite familiar with.我正在试验 Javax/JaxRs,我正在使用 WildFly 25 服务器,我不太熟悉它。

Searching for something similar to Spring's Actuator, I stumbled across the metrics & health endpoints the server exposes by default, and its ability to add custom counters, gauges etc. to application endpoints.在搜索类似于 Spring 的 Actuator 的东西时,我偶然发现了服务器默认公开的指标和健康端点,以及它向应用程序端点添加自定义计数器、仪表等的能力。

However, whatever I do, these custom endpoints are not exposed under the default http://localhost:9990/metrics URL.但是,无论我做什么,这些自定义端点都不会在默认的 http://localhost:9990/metrics URL 下公开。

I am following the guide provided by WildFly under the GitHub repository: https://github.com/wildfly/quickstart/tree/main/microprofile-metrics我正在遵循 GitHub 存储库下 WildFly 提供的指南: https : //github.com/wildfly/quickstart/tree/main/microprofile-metrics

There are some "red flags" on the tutorial that do not seem to be working with whatever I try to do.教程中有一些“危险信号”,无论我尝试做什么,它们似乎都不起作用。

  1. The guide suggests that if we want to get the metrics in JSON format, we need to use the following header: " Accepted: application/json ", which still returns the default Prometheus format, both in Postman and Curl.该指南建议,如果我们想以 JSON 格式获取指标,我们需要使用以下标头:“ Accepted: application/json ”,它仍然返回默认的 Prometheus 格式,在 Postman 和 Curl 中。
  2. The guide also suggests that metrics/vendor , metrics/application , metrics/base return metrics of different scopes, which to my test, they all return the same.该指南还建议metrics/vendormetrics/applicationmetrics/base返回不同范围的指标,在​​我的测试中,它们都返回相同的指标。

As far as the tutorial code is concerned, I tried running it on the Jakarta EE 8 Full & Web Distribution but it throws the following error:就教程代码而言,我尝试在 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

I tried compiling the code with different versions of Java (1.8, 11, 17) hoping that it may fix the problem but to no avail.我尝试使用不同版本的 Java(1.8、11、17)编译代码,希望它可以解决问题,但无济于事。

However, using the WildFly Preview EE 9.1 Distribution seems to stop throwing the error, but the custom metrics still do not to work.然而,使用 WildFly Preview EE 9.1 Distribution 似乎停止抛出错误,但自定义指标仍然不起作用。

There are the subsystems that I added to both distributions during my tries (taken from standalone.xml):我在尝试期间添加到两个发行版中的子系统(取自 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"/>

(others omitted for brevity) (为简洁起见,其他省略)

I also tried enabling the statistics by creating the following bat and launching it:我还尝试通过创建以下 bat 并启动它来启用统计信息:

call standalone.bat -Dwildfly.statistics-enabled=true

I am using IntelliJ, so I tried doing the same from within the IDE:我正在使用 IntelliJ,所以我尝试在 IDE 中执行相同的操作: IDE 启动配置

(the "enable statistics" option was added both to VM options & on the bat during launch to make sure it works) (“启用统计”选项在启动期间已添加到 VM 选项和 bat 中,以确保其正常工作)

Here are the dependencies that I am using, based on my server's version:以下是我使用的依赖项,基于我的服务器版本:

<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>

It looks like you're using standalone.xml configuration.看起来您正在使用standalone.xml配置。 While that does have a metrics extension, it's not MP Metrics.虽然它确实有一个指标扩展,但它不是 MP Metrics。 For that, you would need to use standalone-microprofile.xml .为此,您需要使用standalone-microprofile.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM