Chapter 7. Develop Micrometer application for JBoss EAP
7.1. Integrating Micrometer metrics in JBoss EAP Copy linkLink copied to clipboard!
Using Micrometer, you can monitor and collect application metrics in JBoss EAP. Micrometer support provides the exposure of application metrics. The export process is PUSH-based, ensuring that metrics are sent to an OpenTelemetry Collector.
Prerequisites
- You have installed JDK 17.
- You have installed the Maven 3.6 or later version. For more information, see Downloading Apache Maven.
- You have installed Docker. For more information, see Get Docker.
- Optional: You have podman installed on your system. Use the latest podman version available on supported RHEL. For more information, see Red Hat JBoss Enterprise Application Platform 8.0 Supported Configurations.
-
The
configure-micrometer.clifile is available in the application root directory.
The example in this section, including how to use the configure-micrometer.cli file, is based on the Micrometer Quickstart.
Procedure
- Open a terminal.
Start JBoss EAP as a standalone server by using the following script:
<EAP_HOME>/bin/standalone.sh -c standalone-microprofile.xml
$ <EAP_HOME>/bin/standalone.sh -c standalone-microprofile.xmlCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteFor Windows server, use the
<EAP_HOME>\bin\standalone.batscript.- Open a new terminal.
- Navigate to the application root directory.
Run the following command to configure the server:
<EAP_HOME>/bin/jboss-cli.sh --connect --file=configure-micrometer.cli
$ <EAP_HOME>/bin/jboss-cli.sh --connect --file=configure-micrometer.cliCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteFor Windows server, use the
<EAP_HOME>\bin\jboss-cli.batscript.Replace <EAP_HOME> with the path to your server.
Expected output:
The batch executed successfully process-state: reload-required
The batch executed successfully process-state: reload-requiredCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the server with the following management command:
<EAP_HOME>/bin/jboss-cli.sh --connect --commands=reload
$ <EAP_HOME>/bin/jboss-cli.sh --connect --commands=reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a configuration file named
docker-compose.yamlwith the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a configuration file named
otel-collector-config.yamlwith the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start the collector server instance by running the following command:
docker-compose up
$ docker-compose upCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou can also use Podman instead of Docker. If you choose Podman, then use the
$ podman-compose upcommand instead of$ docker-compose up. If Docker or Podman is not supported in your environment, then see Otel Collector documentation for guidance on installing and running the OpenTelemetry Collector.In the
RootResourceclass, see how theMeterRegistryis injected into your class to ensure proper setup before registering the meters.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Inspect the
checkIfPrime()method body to see how to use the registered meters within your application logic. For example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Navigate to the application root directory.
Syntax
cd <path_to_application_root>/<application_root>
$ cd <path_to_application_root>/<application_root>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example, in reference to the Micrometer Quickstart:
cd ~/quickstarts/micrometer
$ cd ~/quickstarts/micrometerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Compile and deploy the application with the following command:
mvn clean package wildfly:deploy
$ mvn clean package wildfly:deployCopy to Clipboard Copied! Toggle word wrap Toggle overflow
This deploys micrometer/target/micrometer.war to the running server.
Verification
Access the application by using a web browser or you can run the following command.
curl http://localhost:8080/micrometer/prime/13
$ curl http://localhost:8080/micrometer/prime/13Copy to Clipboard Copied! Toggle word wrap Toggle overflow Expected output:
13 is prime.
13 is prime.Copy to Clipboard Copied! Toggle word wrap Toggle overflow