【问题标题】:MicroProfile Metrics do not show custom metrics on Wildfly 25MicroProfile Metrics 不显示 Wildfly 25 上的自定义指标
【发布时间】: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

教程中有一些“危险信号”似乎不适用于我尝试做的任何事情。

  1. 该指南建议,如果我们想要获取 JSON 格式的指标,我们需要使用以下标头:“Accepted: application/json”,它仍然返回默认的 Prometheus 格式,无论是 Postman 还是 Curl。
  2. 该指南还建议 metrics/vendormetrics/applicationmetrics/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


    【解决方案1】:

    约翰。我是 WildFly 的 Metrics/MP Metrics 组件负责人,希望我能帮助您解决问题。

    在我对挖掘 WF 源代码感到兴奋之前,您能确认一下您使用的是哪种配置吗?看起来您正在使用standalone.xml 配置。虽然它确实有一个指标扩展,但它不是 MP 指标。为此,您需要使用standalone-microprofile.xml。

    希望您的问题就这么简单。如果没有,请告诉我,我们将深入挖掘。 :)

    【讨论】:

    • 嗨,杰森,感谢您的回复。是的,我正在运行standalone.xml 配置,它的行为似乎有所不同。我可以确认使用standalone-microprofile.xml 就像一个魅力!我刚刚通过以下方式启动了 bat 文件:“standalone.bat -c Standalone-microprofile.xml”。非常感谢!附言有没有办法为默认配置启用 MP Metrics?提前致谢。
    • 试试这个:jboss-cli.sh -c "/extension=org.wildfly.extension.microprofile.metrics-smallrye:add()" && jboss-cli.sh -c "/subsystem= microprofile-metrics-smallrye:add()" && jboss-cli.sh -c reload
    • 请尽量减少无关信息,不要在您的解决方案中提出澄清问题。这就是 cmets 的用途。
    猜你喜欢
    • 2022-08-19
    • 2022-12-13
    • 2020-12-01
    • 2019-11-18
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-24
    相关资源
    最近更新 更多