I would like to monitor a remotely running java (spring boot) application with jvisualvm (or jconsole). When running locally, I can see the managed beans in both jvisualvm and
Let me discuss it in detail. I've just connected it to the remote server. U need to go to the folder where your jar file is. Suppose, you want to monitor X.jar file and suppose it is located in usr/local/ folder.. So, first cd into that folder. Then be sure which jdk is running. You can find it by executing command which java in linux. In the command line of the remote server (generally we use PuTTy cmd). In the puTTy cmd write :
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.10.0 -jar X.jar
Now let me explain in detail. Here, rmi port is needed to be defined because jmx uses rmi. If we don't define rmi port, it will automatically assign a random port. Then our connection won't be successful. We won't use authentication and ssl because this will cause difficulties. You can try this on your own if you want. In the hostname, you must specify your remote hostname which is the IP address. Now use visualvm located in your local computer. Generally, it can be found in this folder:
C://Program Files/Java/jdk1.8.0_201/bin
If not then download it and paste it into the directory. Run visualvm from your local pc. You will see some options like local, remote. In the "remote" option select "Add Remote Host". Add your hostname. In my case, it was 192.168.10.0. Then right-click on your mouse and select "Add jmx connection". A window will open and insert your port number. In my case, it was 9010. You can specify any port number. Select "do not require ssl connection" and don't select the security credentials. Because we've added in the properties that authentication is false. Now connect and your connection will go smoothly. One more suggestion. You can connect using "jstatd connection. But it doesn't work. Doesn't show any output. Maybe because java 8 problems or so. For monitoring memory details you will need an updated version of "visualvm.exe". You can download it. You can connect using Authentication and SSL. The detailed steps using Authentication=true is discussed in this link: Connect to remote JMX Agent with authentication
The detailed steps using both authentication=true and SSL = true is discussed in this link: JConsole SSL/TLS with Password Authentication
Arnab Biswas's anwser not work in my case. After an hour of researching, I found out that JMX runs on top of RMI, and as such, there are 2 ports that JMX utilizes:
-Dcom.sun.management.jmxremote.port
)-Dcom.sun.management.jmxremote.rmi.port
)RMI data port will open a random port start from 1099
. By setting the port used by the RMI registry and the RMI server to the same port, tunneling will be much easier.
So I need to add -Dcom.sun.management.jmxremote.rmi.port=9010
to JVM options
And I need to use the following JVM options :
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.59.99
Read more:
Please use the following JVM options :
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.59.99
In the Jconsole use the following to connect:
service:jmx:rmi:///jndi/rmi://192.168.59.99:9010/jmxrmi