Example code accompanying the blog post "Monitoring REST APIs with JDK Flight Recorder Custom Events". It shows how to use custom event types with JDK Flight Recorder and Mission Control to gain insight into runtime performance of a JAX-RS based REST API. It also demonstrates how to export Flight Recorder events in realtime via MicroProfile Metrics, using the JDK Flight Recorder event streaming API (JEP 349) added in Java 14.
Update Feb. 8th: the example has been expanded to show the usage of the JFR datasource for Grafana.
Clone the repository by running
git clone [email protected]:gunnarmorling/jfr-custom-events.git --recurse-submodules
The --recurse-submodules
ensures that the jfr-datasource sub-module will be cloned as well.
If you have cloned the repository omitting that option, you can run git submodule update --init --recursive
for updating the sub-module.
Make sure to have Java 17 installed. Run the following to build this project:
# Example service
mvn clean package -f example-service/pom.xml
# JFR datasource for Grafana
mvn clean package -f jfr-datasource/pom.xml
docker-compose up --build
Open the web application at http://localhost:8080/. You then can connect to the running application on port 1898 using Mission Control, start Flight Recorder and observe "JAX-RS" events in the recording. You also can observe the exported metrics via Grafana at http://localhost:3000/.
When working on the example service, it can be started in the Quarkus dev mode instead of packaging it as a container image for faster feedback;
docker-compose up --build --scale example-service=0
mvn compile quarkus:dev -f example-service/pom.xml
When starting a recording, make sure to use the process for target/flight-recorder-demo-dev.jar.
The JFR datasource has been setup in Grafana. To examine a JFR recording, load it into the datasource:
curl -F "file=@/path/to/my/recording.jfr" localhost:8081/load
Then open the "JFR Events" dashboard in Grafana and zoom into the time range of the recording.
This code base is available ander the Apache License, version 2.