Gangmax Blog

Profile Spring Boot Web Application with JConsole

This post describes how to profile a Spring Boot web application with JConsole(the default profiling tool provided by JDK).

  1. Start the Spring Boot web application with JMX enabled(from here).
1
2
3
4
5
# Start the Spring Boot web application. This command will enable the JMX service on port 6001.
java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=6001 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=10.80.20.119 \
-Dcom.sun.management.jmxremote.rmi.port=6001 -jar webapp-0.0.1-SNAPSHOT.jar > /dev/null 2>&1 &

Notes:

a. With the “-D” arguments, the web application enables the JMX service on port 6001.

b. You need to incidate the current server’s IP in the “-Djava.rmi.server.hostname” argument.

  1. Open the port used by JMX in Firewall. If you server has firewall, you need this step. In my case, it’s a CentOS with the “firewall-cmd”.
1
2
3
sudo firewall-cmd --zone=public --add-port=6001/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
  1. Use JConsole to connect.

Open JConsole, enter “10.80.20.119:6001” to connect the RMI port.

Now it everything works, you can see the profiling result charts in JConsole(memory, CPU, classes, threads & etc).

Comments