Java Flight Recorder Management Documentation
This documentation describes two scripts: one for starting and another for stopping Java Flight Recorder (JFR), as well as instructions on how to download, install, and run Java Mission Control.
Starting Java Flight Recorder: start_jfr.sh
What it does:
The first script is responsible for starting Java Flight Recorder (JFR) on a specific pod in a Kubernetes namespace. The script does the following:
- Defines the necessary environment variables like the Kubernetes namespace, recording name, settings, and pod prefix.
- Connects to the remote server using SSH with a specified user.
- Finds the pod by matching the provided prefix.
- Starts the JFR on the Java process inside the pod using
jcmd, with a specified recording name, settings, and a duration of999 hours. - The JFR recording is saved to a specific file path inside the pod.
Variables:
VPS_HOST: The remote server's hostname or IP address.SSH_USER: The username for SSH.NAMESPACE: Kubernetes namespace where the pod resides.RECORDING_NAME: The name of the JFR recording.SETTINGS: The Java Flight Recorder settings.POD_PREFIX: The prefix used to find the pod.
Stopping Java Flight Recorder: stop_jfr.sh
What it does:
The second script stops an active Java Flight Recorder (JFR) session on a specific pod in the Kubernetes namespace and downloads the recording file. The script performs the following actions:
- Defines environment variables like Kubernetes namespace, recording name, and pod prefix.
- Connects to the remote server using SSH with the provided user credentials.
- Finds the pod based on the prefix.
- Stops the JFR session using
jcmdand the previously started recording name. - Downloads the recording from the pod using
kubectl cpand then transfers it from the remote server to the local machine usingscp.
Variables:
VPS_HOST: The remote server's hostname or IP address.SSH_USER: The username for SSH.NAMESPACE: Kubernetes namespace where the pod resides.RECORDING_NAME: The name of the JFR recording to stop.POD_PREFIX: The prefix used to find the pod.FILENAME: The file path where the JFR recording is stored inside the pod.
How to Install and Run Java Mission Control (JMC)
Here's how to install and run it on Linux:
Step 1: Download Java Mission Control
- Visit the Official JMC Download Page.
- Download the latest version of the Java Mission Control package for Linux.
Step 2: Install Java Mission Control
- Extract the downloaded
.tar.gzarchive:tar -xzf <path-to-jmc-tar.gz> -C /opt - Optionally, create a symbolic link to make it easier to run:
sudo ln -s /opt/jmc/jmc /usr/local/bin/jmc
Step 3: Launch Java Mission Control
You can now launch JMC from the terminal:
/opt/jmc/jmc
Or, if you created the symbolic link:
jmc
Step 4: Open JFR Recording
Once JMC is open, you can open JFR file that was downloaded using the second script.