Azul Intelligence Cloud The Powerful Analytics Solution That Boosts DevOps Efficiency with Insights from Production Java Runtime Data from Any JVM  
Support
Blog chevron_right Java

Remotely Record a JFR Log from a Container

(Without Using the Command Line)

This blog post assumes a working knowledge of Java virtual machines and of Java Flight Recorder (JFR) and JFR logs. To make best use of this article, you should have Azul Mission Control installed and ready to run.

Java Flight Recorder (JFR) is the go-to technology for recording and viewing JVM and system metrics. JFR logs reveal much about the running application, the health of the JVM, and the stability of the system. You can access JFR logs easily by simply going into the command line / terminal and entering a few commands. But what if you don’t have access to the command line or terminal directly on the system where the JVM is running, like when the JVM is running in a container? Don’t worry. In this quick guide, you will learn how to obtain JDR logs with little configuration using JVM’s JMX connector and Azul Mission Control.

Set up JMX on your JVM

Before you can access your JVM outside of the command line / terminal, you must set up your JVM to be discoverable and accessible over remote connections. You can accomplish this simply by enabling the JVM’s JMX connector. Configure your Java application with the following VM parameters:

  • -Dcom.sun.management.jmxremote: enables JMX/JMXRMI connectivity.
  • -Dcom.sun.management.jmxremote.host=<IP/Hostname>: Sets the address for JMX connection. Use an external IP address or host name of the computer or container where the Java program is running.
  • -Dcom.sun.management.jmxremote.port=<port>: Sets the TCP port for JMX connection.
  • -Djava.rmi.server.hostname=<IP/hostname>: Sets the address for JMXRMI connection. Use the same IP/hostname you used for JMX connection.
  • -Dcom.sun.management.jmxremote.rmi.port=<port>: Sets the TCP port for JMXRMI connection. Use the same TCP port you used for JMX connection.
  • -Dcom.sun.management.jmxremote.local.only=false: If you are connecting to the JVM from a different machine, you have to unbind ports from localhost.
  • Additionally, you may want to enable JMX authentication/SSL using:
    • ‑Dcom.sun.management.jmxremote.authenticate=true
    • -Dcom.sun.management.jmxremote.ssl=true

For example:

-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.host=192.168.0.166 \
-Dcom.sun.management.jmxremote.port=7091 \
-Djava.rmi.server.hostname=192.168.0.166 \
-Dcom.sun.management.jmxremote.rmi.port=7091 \
-Dcom.sun.management.jmxremote.local.only=false \
‑Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \

Connect to a Remote JVM Using Azul Mission Control

If you don’t have Azul Mission Control yet, head over to the Azul Mission Control download page.

In Azul Mission Control, go to the JVM Browser and click the Add JVM Connection button to create a new custom JVM connection.

Specify the host name/IP address of the remote system and the JMX port number.

If JMX authentication is enabled, enter User and Password.

Click Test Connection to make sure your remote JVM is reachable and click Finish.

Your remote JVM now appears in the JVM Browser.

Depending on your network and container setup, port forwarding may need to be set up. Contact your network’s administrator if you need help with port forwarding.

Record a JFR from your Remote JVM

Now that you’re connected to your JVM remotely, it’s time to make a JFR recording.

In Azul Mission Control, go to the JDK Browser, right-click your remote JVM connection and select Start Flight Recording…

Select your preferred options and time intervals (either a fixed time recording or continuous recording based on the JFR log’s size and/or age), and click Finish.

Your remote JFR recording has begun. You’re almost there!

Check the progress of the recording by expanding the remote JVM connection in the JVM Browser.

Once your recording has finished, your JFR log opens automatically in Azul Mission Control. You can now check the Outline tab to take a deeper look into your JVM’s performance portfolio.

Your Turn

Download Azul Mission Control

Note: This is an edited version of an article that originally ran on The New Stack on June 24, 2024.