Forum Stats

  • 3,875,456 Users
  • 2,266,916 Discussions
  • 7,912,219 Comments

Discussions

Can flight recording be triggered programatically?

Andy Dufresne
Andy Dufresne Member Posts: 138
edited Sep 7, 2015 9:26AM in Java Mission Control

Java mission control's flight recording feature looks great and seems to be perfect for troubleshooting production issues for e.g. high cpu. I had a question - Can the flight recording be triggered programmatically from with the java application? I understand that flight recording could be triggered through jvm options like -XX:StartFlightRecording=duration=60s,filename=myrecording.jfr but this is not what I am referring too. I am also aware of the fact that using flight recording in production environments requires a Java SE Advanced License.

I see two advantages in doing programmatic triggering of the flight recording

1. Avoids manual intervention in connecting to all production environments (which seems practically impossible when there are more than hundreds of jvms running)?

2. Less reliability on the support & operations team to know how to do flight recording?

I visualize it to be triggered by a thread which monitors jmx metrics periodically (for e.g. ProcessJVMLoad) and triggers a flight recording if the value goes above 90% (for 3 times consecutively). The flight recording could be a specific duration and the location could be picked from configuration.

Best Answer

  • Hirt-Oracle
    Hirt-Oracle Member Posts: 268
    edited Feb 19, 2015 11:12AM Answer ✓

    Hi Andy,

    Seems JConsole can't handle more complex parameters. Instead use the JMC JMX console. The JMC JMX Console even has a special tab where you can play around with the diagnostic commands.

    The Flight Recorder MBean must be properly initialized and registered. If you use JMC to start a recording, for example, it will be initialized. So one way you can play around with it, it to first start a recording, then use the JMC JMX Console to play around with the MBean. I am reluctant to post code here on how to use that MBean since it is unsupported.

    To invoke the DiagnosticCommandMBean with programmatically, simply do it like you would any remote JMX operation.

    Kind regards,

    Marcus

Answers

  • Hirt-Oracle
    Hirt-Oracle Member Posts: 268
    edited Feb 19, 2015 4:20AM

    Yes. There are several ways of doing this. The easiest would probably be to use a diagnostic command over JMX. The other, a little bit more complicated and very unsupported and undocumented, would be to use the FlightRecorder MBean. The advantage of the latter would be the ability to stream back the data over JMX.

    Andy Dufresne
  • Hirt-Oracle
    Hirt-Oracle Member Posts: 268
    edited Feb 19, 2015 4:26AM

    Here is how to execute diagnostic commands using attach (Executing Diagnostic Commands Using Attach | Marcus Hirt), locally running JVMs only. For JMX, use the com.sun.management:type=DiagnosticCommand MBean.

  • Andy Dufresne
    Andy Dufresne Member Posts: 138
    edited Feb 19, 2015 5:19AM
    1. Ok I could find the diagnostic command mbean but not the flight recorder mbean. Please see the attached image (ListOfMbeans). I had started my jvm with these jvm options -XX:+UnlockCommercialFeatures -XX:+FlightRecorder. ListOfMbeans.png
    2. Also the operations of Diagnostic command mbean are disabled on my jconsole. What could be the reason?DiagnosticCommandMBean.png
    3. Is there an api through which this flight recording can be triggered?
  • Hirt-Oracle
    Hirt-Oracle Member Posts: 268
    edited Feb 19, 2015 11:12AM Answer ✓

    Hi Andy,

    Seems JConsole can't handle more complex parameters. Instead use the JMC JMX console. The JMC JMX Console even has a special tab where you can play around with the diagnostic commands.

    The Flight Recorder MBean must be properly initialized and registered. If you use JMC to start a recording, for example, it will be initialized. So one way you can play around with it, it to first start a recording, then use the JMC JMX Console to play around with the MBean. I am reluctant to post code here on how to use that MBean since it is unsupported.

    To invoke the DiagnosticCommandMBean with programmatically, simply do it like you would any remote JMX operation.

    Kind regards,

    Marcus

  • 2993324
    2993324 Member Posts: 2
    edited Jul 16, 2015 12:06PM

    Hello!

    The Flight Recorder MBean must be properly initialized and registered. If you use JMC to start a recording, for example, it will be initialized. So one way you can play around with it, it to first start a recording, then use the JMC JMX Console to play around with the MBean. I am reluctant to post code here on how to use that MBean since it is unsupported.
    

    Could you please post the code here on how to use that MBean. I have successfully created the HotSpotVirtualMachine in the code, but now I am stuck which command to pass to the executeJCmd method to start the Flight Recorder. This would really help me with getting the measurements for my masters degree. Thank you!

  • 8361024a-6c99-4785-a81a-2f022bce4aa8
    edited Aug 20, 2015 1:49PM

    Hi,

    I believe that this feature is not supported by Oracle but I wrote some code to do that: https://github.com/cykl/unportant-jfr. I use it to programmatically manage JFR from Hadoop jobs.

    This code is only a POC: not been battle tested & not officially released. Use it, or copy-paste it, at your own risk. Oracle can break the compatibility in a later update too..

    Regards.

  • 2993324
    2993324 Member Posts: 2
    edited Sep 7, 2015 4:59AM

    Thank you very much for this code. I was hoping that there would be something official from Oracle, but nonetheless open source variant is even better. Will try and report back if I find any troubles.

  • M.Fevzi Korkutata
    M.Fevzi Korkutata Member Posts: 11 Bronze Badge
    edited Sep 7, 2015 9:26AM

    You can try WLSDM, it's interacted with WebLogic MBean metrics..

This discussion has been closed.