Skip to content

gunnarmorling/jfr-custom-events

Repository files navigation

JDK Flight Recorder Custom Events

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.

Custom Flight Recorder Events in JDK Mission Control

Metrics for Flight Recorder Events in Grafana

Update Feb. 8th: the example has been expanded to show the usage of the JFR datasource for Grafana.

Checking Out the Sources

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.

Build

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

Dev Mode

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.

Loading JFR Recordings into Grafana

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.

JFR Datasource in Grafana

License

This code base is available ander the Apache License, version 2.

About

Demo of Java Flight Recorder custom events and event streaming

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •