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
# Start the Spring Boot web application. This command will enable the JMX service on port 6001.
2
java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=6001 \
3
-Dcom.sun.management.jmxremote.authenticate=false \
4
-Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=10.80.20.119 \
5
-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
sudo firewall-cmd --zone=public --add-port=6001/tcp --permanent
2
sudo firewall-cmd --reload
3
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