Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8248564

JFR: Remote Recording Stream

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • 14, 16
    • 16
    • hotspot
    • jfr
    • b27

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              egahlin Erik Gahlin
              egahlin Erik Gahlin
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: