0

I have a java process running (on java 7) on some remote server that I want to monitor using Java Mission Control. However, JMC is unable to connect, although I can telnet to the server using the port jmx remote port (12345 here, see below).

The remote java proces is started with

-Dcom.sun.management.jmxremote=true 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.port=12345 
-Djava.rmi.server.hostname=<some ip address>
-Dcom.sun.management.jmxremote.authenticate=false

and these seem to be correct values to me. Port 12345 has been opened on the firewall, but I suspect that the rmi server port is blocked by the firewall.

Thus, my question is: Is there any way (using netstat on the server or maybe even telnet from the client) to determine which rmi server port the java process is currently using on the server? (Using netstat, I see several ports being used by the java process. However, I don't have a clue which one is the rmi port.)

user1993047
  • 33
  • 1
  • 7
  • If the firewall is blocking it you will get a connection timeout. If you're gettig something else please confide in us. The answer to your actual question is to read the configuration, which you've already done. – user207421 Sep 03 '15 at 12:34
  • The output of JMC is not very telling. I only states "Could not connect" or so. And it takes very long. So, yes, I guess that's a connection timeout ... :) – user1993047 Sep 03 '15 at 14:33
  • About the configuration: As I understand it, there is a jmx port and an rmi port. The above configuration only specifies a jmx port, I was wondering whether there is some way to find out the rmi port (using netstat gives me a handful of ports which my java process is listening to). – user1993047 Sep 03 '15 at 14:37
  • Ok. Right now I just opened all ports that my java process is listening to and JMC can now connect. Would still be nice to know the exact RMI port. Will try dave_thompsons suggestion. – user1993047 Sep 04 '15 at 20:37

2 Answers2

0

This should display where a JMX remote client is told to connect to (plus some internal info) possibly after timing out:

//nopackage -- move if you like
import java.rmi.Remote;
import java.rmi.registry.*;
import java.rmi.server.*;
import sun.rmi.server.UnicastRef;
import sun.rmi.transport.LiveRef;

public class JMXTarget {
    /*
     * run: java JMXTarget host port
     * where host (name or address) contains the JVM process offering JMX
     * and port (number) is the registry specified by -Dcom.sun.management.jmxremote.port 
     */
    public static void main(String[] args) throws Exception {
        Registry reg = LocateRegistry.getRegistry (args[0], Integer.parseInt(args[1]));
        Remote r = reg.lookup ("jmxrmi");
        RemoteObject ro = (RemoteObject)r; 
        RemoteRef rr = ro.getRef();
        UnicastRef ur = (UnicastRef)rr;
        LiveRef lr = ur.getLiveRef();
        System.out.println (lr);
    }
}

Note if sysprop java.rmi.server.hostname is specified as you did, its value (your "some ip address") is where the client connects. If that value is not an address of the target machine, or a name that resolves (for the client) to an address of the target machine, it won't connect. If you don't specify it, it defaults to (edit) the value determined by InetAddress.getLocalHost() which is or at least should be a valid address for that machine.

dave_thompson_085
  • 34,712
  • 6
  • 50
  • 70
0

Adding '-Dcom.sun.management.jmxremote.rmi.port=12345' could help

See Why Java opens 3 ports when JMX is configured?

Community
  • 1
  • 1
Klara
  • 2,935
  • 22
  • 19