简体   繁体   中英

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.

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.

However, whatever I do, these custom endpoints are not exposed under the default 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

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

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:

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.

However, using the WildFly Preview EE 9.1 Distribution seems to stop throwing the error, but the custom metrics still do not to work.

There are the subsystems that I added to both distributions during my tries (taken from 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:

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

I am using IntelliJ, so I tried doing the same from within the IDE: IDE 启动配置

(the "enable statistics" option was added both to VM options & on the bat during launch to make sure it works)

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. While that does have a metrics extension, it's not MP Metrics. For that, you would need to use standalone-microprofile.xml .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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