Search code examples
javaspring-bootjvmvisualvmjvm-arguments

How to connect Spring Boot application remotely in Visual VM?


I am new to Visual VM, how to connect to Spring Boot application remotely in Visual VM?

Multiple instances are running as a java -jar app.jar with random ports. How to connect from Visual VM, I have root access to the remote system. Do I need to enable any security configuration?

In the local system, applications shows up automatically but when I entered remote system IP address it's prompting Add JMX connection and Add jstatd connection.

VisualVM


Solution

  • We need to specify the remote IP ADDRESS and expose the listening PORT while running the jar.

    Syntax:

    java 
    -Dcom.sun.management.jmxremote=true 
    -Dcom.sun.management.jmxremote.port=<PORT> 
    -Dcom.sun.management.jmxremote.authenticate=false 
    -Dcom.sun.management.jmxremote.ssl=false 
    -Djava.rmi.server.hostname=<IP_ADDRESS>
    -Dcom.sun.management.jmxremote.rmi.port=<PORT> 
    -jar app-1.0.0-SNAPSHOT.jar 
    

    Example: Listening port is 6001 and available for remote ip address 192.168.0.23

    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=192.168.0.23 -Dcom.sun.management.jmxremote.rmi.port=6001 -jar app-1.0.0-SNAPSHOT.jar 
    

    For More details about set up Visual VM https://github.com/M-Thirumal/installation_guide/blob/master/visualVm/visualvm_remote_set_up.md