25.4.2. 使用 HTTP 端点检查指标

指标在 JBoss EAP 管理界面上自动可用,包含以下上下文可用:

  • /metrics/ - 包含 MicroProfile 3.0 规范中指定的指标。
  • /metrics/vendor - 包含特定于供应商的指标,如内存池。
  • /metrics/application - 包含来自使用 MicroProfile 指标 API 的部署和子系统的指标。

JBoss EAP 子系统指标以 Prometheus 格式公开。

指标名称基于子系统和属性名称。例如,undertow 子系统为应用部署中的每个 servlet 公开指标属性 request-count。此指标的名称为 jboss_undertow_request_count。前缀 jboss 有助于识别指标来源。

要查看 EAP 公开的指标列表,可在 CLI 中执行以下命令:

$ curl -v http://localhost:9990/metrics | grep -i type

示例:获取 JAX-RS 应用的请求数

以下示例演示了如何查找向 JBoss EAP 上部署的 Web 服务发出的请求数。该示例使用 helloworld-rs quickstart 作为 Web 服务。下载快速入门自:jboss-eap-quickstarts.

在 helloworld -rs 快速启动中检查 request-count 指标:

  1. undertow 子系统启用统计信息:

    • 在启用了统计信息的情况下启动单机服务器:

      $ ./standalone.sh -Dwildfly.statistics-enabled=true
    • 对于已经运行的服务器,启用 undertow 子系统的统计信息:

      /subsystem=undertow/:write-attribute(name=statistics-enabled,value=true)
  2. 部署 helloworld-rs 快速入门:

    • 在快速启动的根目录中,使用 Maven 部署 Web 应用程序:

      $ mvn clean install wildfly:deploy
  3. 使用 curl 命令在 CLI 中查询 http 端点,并为 request_count 过滤:

    $ curl -v http://localhost:9990/metrics |  grep request_count

    输出:

    jboss_undertow_request_count_total{server="default-server",http_listener="default",} 0.0

    返回的属性值为 0.0

  4. 在 Web 浏览器中访问位于 http://localhost:8080/helloworld-rs/ 的快速入门,再单击任何链接。
  5. 通过 CLI 再次查询 http 端点:

    $ curl -v http://localhost:9990/metrics |  grep request_count

    输出:

    jboss_undertow_request_count_total{server="default-server",http_listener="default",} 1.0

    该值更新至 1.0

    您可以通过重复最后两个步骤来验证请求数是否正确更新。