Search code examples
javalinuxjmxvisualvm

Can't connect to remote JMX host


Using VisualVM, there are two types I can see to connect remote host.

  1. jstatd

  2. JMX

So I am trying to use JMX, I followed numerous tutorials but no luck so far.

Currently, there's my desktop and one linux box with java server application running. I am trying to setup VisualVM client on desktop to see java application running on the linux box.

I added following JAVA_OPTS script on start.sh script for the java application on linux.

JMX_PORT="-Dcom.sun.management.jmxremote.port=33333"  <-- allowed on firewall
JMX_SSL="-Dcom.sun.management.jmxremote.ssl=false"
JMX_AUTH="-Dcom.sun.management.jmxremote.authenticate=false"
JMX_IP="-Djava.rmi.server.hostname=xx.xx.xx.xx"   <-- where linux box NAT ip.

Java application on linux was successfully started with jmx options added start.sh, I assume since there's no error or warning.

When I tried to add JMX connection, it says it can't connect to it.

I checked if 33333 is blocked, it's not, I was able to connect to that ip with port using telnet from my desktop.

Is there any other port that I should open for VisualVM?

To use JMX, is there any other setup that I have to do such as RMI Registry server or jstatd policy file creation and start jstat daemon?? I thought it was for jstatd connection only so I didn't pursue that tutorial.


Solution

  • I had no other clue how I can fix this so ended up using ssh tunnel.

    1. I added jmx run option into my java application start script on remote host. (jmxremote.port=33300, ssl to false, authenticate to false, hostname.)
    2. ssh -D 33300 on desktop to remote host.
    3. start jvisualvm using system_socks_proxy=localhost:33300 -J-Djava.net.useSystemProxies=true

    Now remote host is successfully added using add new jmx connection on VisualVm.

    ref. VisualVM over ssh