Search code examples
javajmcjfr

trying to automate java mission control, is it possible?


Is it possible to automate the java mission control to dump a 1 minute flight recording to a folder every hour?

For example : a server is running an application 24/7 and I would love to have the .jfr file automatically dumped to a file every hour


Solution

  • Have a cronjob that does jcmd JFR.dump, at least for JDK 11 it has begin/end parameters.

    $ java -XX:StartFlightRecording MyApp
    

    Then create a dump script, for example

    jcmd MyApp JFR.dump filename=/dumps begin=-1m
    

    Then add a cronjob

    $ crontab -e.
    

    with an entry for the script:

    */60 * * * * /scripts/dumpjfr.sh
    

    For older versions you might have to use the FlightRecorder MXBean if you want to control how much you dump, or set the maxage of the recording to one minute using -XX:StartFlightRecording=maxage=1m. If you want to keep a longer history, multiple recordings can be started with different maxage.

    See for example http://isuru-perera.blogspot.com/2015/02/java-flight-recorder-continuous-recordings.html