I tried to enable JMX remoting on a Java app running on a server by adding the JVM args -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9001 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=xxx.xxx.xxx.xxx
, but I was unable to connect to the application. Not knowing if the application was messing it up somehow, I wrote a simple test app:
public class Main {
public static void main(String[] args) {
while (true) {
try {
System.out.println("Sleeping for 5 seconds...");
Thread.sleep(5000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
However, I could not connect to this application, either. iptables shows an open port on 9001, and netstat confirms that a connection was established, but Jconsole (and a simple Groovy script) fails due to timeout.
Because my troubleshooting has failed thus far, I've been looking into alternative ways of getting Jconsole to connect. Solutions include installing a new webserver and routing JMX through that, but that is probably not feasible for me. There is a webserver on the box but it is Hiawatha and I can't change that or install another one. What have I missed?
Best Answer
Try these steps to troubleshoot and report back:
Can you use
telnet xxx.xxx.xxx.xxx 9001
from where you run the jconsole. You should see:Connected to xxx.xxx.xxx.xxx Escape character is '^]'.
If you do see that then that means you have a TCP connection so firewalls are not the problem.
Run the following command on the server and post the output:
$ netstat -an | grep LISTEN | grep 9001 tcp6 0 0 :::9001 :::* LISTEN
Your class and your command line:
work ok for me, I can connect to jconsole.
java -version