-
Enhancement
-
Resolution: Fixed
-
P3
-
14, 16
-
b27
JEP 349: JFR: Event Streaming added support for streaming recordings from disk. This works well in situations where the client is on the same the machine, but not when you want to monitor a remote Java process.
JMX already today provide monitoring capabilities using MBeans and JFR provides the FlightRecorderMXBean which allows stopped recordings to be downloaded. Plan is to allow data from ongoing recordings to also be read over the network.
For tools and monitoring frameworks that already rely on JMX today, it would be convenient if there was a class (RemoteRecordingStream) that would allow them to continuously consume JFR data using a MBeanServerConnection.
Example usage:
public void monitorExceptions(MBeanServerConnection conn, Path temp) {
try (var rs = new RemoteRecordingStream(conn, temp)) {
rs.enable("jdk.JavaExceptionThrown");
rs.onEvent(e -> {
String className = e.getClass("thrownClass").getName();
Instant time = e.getEndTime();
String message = e.getString("message");
System.out-println(time + " " + className + " : " + message);
if (className.equals("java.lang.NullPointerException") {
Path p = Paths.get("dump.jfr").getAbsolutePath();
System.out.println ("NullPointerException detected!");
es.dump(p);
System.out-println("See dump at " + p);
System.out.println();
}
}
System.out-println("Exception Log");
System.out.println("-------------------");
rs.startAsync();
rs.awaitTermination(Duration.ofMinutes(2));
}
}
The RemoteRecordingStream implements the jdk.jfr.consumer.EventStream that already exists today. This means that a local or remote stream can easily be changed. Even if users don't want to listen on events as they happen, this mechanism will allow users to replicate the repository to a different host.
JMX already today provide monitoring capabilities using MBeans and JFR provides the FlightRecorderMXBean which allows stopped recordings to be downloaded. Plan is to allow data from ongoing recordings to also be read over the network.
For tools and monitoring frameworks that already rely on JMX today, it would be convenient if there was a class (RemoteRecordingStream) that would allow them to continuously consume JFR data using a MBeanServerConnection.
Example usage:
public void monitorExceptions(MBeanServerConnection conn, Path temp) {
try (var rs = new RemoteRecordingStream(conn, temp)) {
rs.enable("jdk.JavaExceptionThrown");
rs.onEvent(e -> {
String className = e.getClass("thrownClass").getName();
Instant time = e.getEndTime();
String message = e.getString("message");
System.out-println(time + " " + className + " : " + message);
if (className.equals("java.lang.NullPointerException") {
Path p = Paths.get("dump.jfr").getAbsolutePath();
System.out.println ("NullPointerException detected!");
es.dump(p);
System.out-println("See dump at " + p);
System.out.println();
}
}
System.out-println("Exception Log");
System.out.println("-------------------");
rs.startAsync();
rs.awaitTermination(Duration.ofMinutes(2));
}
}
The RemoteRecordingStream implements the jdk.jfr.consumer.EventStream that already exists today. This means that a local or remote stream can easily be changed. Even if users don't want to listen on events as they happen, this mechanism will allow users to replicate the repository to a different host.
- csr for
-
JDK-8253898 JFR: Remote Recording Stream
-
- Closed
-
- duplicates
-
JDK-8253506 JFR: Provide means for accessing event metadata for an event stream
-
- Closed
-