81

I am trying to understand a JMX service URL.

service:jmx:rmi://192.168.30.10:1234/jndi/rmi://192.168.30.10:2344/jmxrmi

It would be great, if someone can help me understand this.

Thanks

Beryllium
  • 12,164
  • 9
  • 52
  • 81
priyank
  • 4,166
  • 10
  • 41
  • 51
  • Related to http://stackoverflow.com/questions/743343/cannot-connect-to-tomcats-mbeanserver-via-jconsole-in-java6 – Gray Mar 27 '12 at 13:21

3 Answers3

107

I will reuse an answer I wrote up earlier for this question: Cannot connect to Tomcat's MBeanServer via jconsole in Java6

It's not complete, but might help:

Suppose you have the JMX Server (alias 'JMX Agent' alias 'the JVM you want to connect to') running on 'TARGET MACHINE' with the RMI registry port at 'RMI REGISTRY PORT' and the JMX RMI server port at 'JMX RMI SERVER PORT'.

Note:

  1. The RMI registry tells JMX clients where to find the JMX RMI server port; information can be obtained under key jmxrmi.
  2. The RMI registry port is generally known as it is set through system properties at JVM startup.
  3. The JMX RMI server port is generally not known as the JVM chooses it at random (if no other precautions are taken).

The following URI will lead to successful connection (tested)

service:jmx:rmi://<TARGET_MACHINE>:<JMX_RMI_SERVER_PORT>/jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi

This looks nasty. Let's cut it apart.

This URI is an RFC2609 "Service Location Protocol URL" (well, it's really an URI, right?)

It is composed of:

  • service - a constant
  • jmx:rmi - the service type composed of: abstract type jmx and URL scheme rmi
  • the rest - the sap (service access protocol specification)

sap is decomposed into:

  • //<TARGET_MACHINE>:<JMX_RMI_SERVER_PORT> - ipsite
  • /jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi - URL part

A well-informed JMX client connects to the "ipsite" to do JMX-over-RMI exchanges; but what of the JMX client that doesn't KNOW that port? Patience...

URL part is decomposed into:

  • /jndi/ - This seems to tell the JMX client that it can get lookup information at the location that follows
  • rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi - Yep, we get information about the JMX RMI Server at the RMI registry, under the lookup key jmxrmi

This is somewhat cart-before-horse, as one has to contact the RMI registry given by the latter part of the SLP URL first.

After scratching head, intuitively, let's try:

service:jmx:rmi://<TARGET_MACHINE>/jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi

Yes, that works! The JMX RMI server port is nicely obtained from the registry. On second thoughts, the target machine should also be obtained from the registry, thus:

service:jmx:rmi:///jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi

Even better, that works, too!

References:

  1. http://download.oracle.com/javase/6/docs/api/javax/management/remote/rmi/package-summary.html
  2. http://download.oracle.com/javase/6/docs/api/javax/management/remote/JMXServiceURL.html
  3. http://mx4j.sourceforge.net/docs/ch03s04.html
  4. http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html#gdevg
  5. http://www.rfc-editor.org/rfc/rfc2609.txt
Community
  • 1
  • 1
David Tonhofer
  • 12,954
  • 4
  • 44
  • 46
7

To explain:

service:jmx:rmi://192.168.30.10:1234/jndi/rmi://192.168.30.10:2344/jmxrmi
  1. service:jmx:rmi://192.168.30.10:1234 - says that there is a JMX Agent on the machine with IP address 192.168.30.10. The JMX agent is using (TCP) port 1234 to provide JMX service(s) over RMI (basically acts as an RMI server).
  2. /jndi/rmi://192.168.30.10:2344/jmxrmi - says that the RMI stub to interact with the JMX Agent over RMI can be found in the RMI registry which is running on the machine with IP address 192.168.30.10 and is using (TCP) port 2344. To get the RMI stub you need to lookup the "jmxrmi" binding.

Previous answers suggest that the 2nd part of the URL is to obtain the server port of the JMX RMI server. That is not correct. The JMX RMI server port is (TCP) 1234 and is part of the URL. What you get from the RMI registry is the RMI stub (javax.management.remote.rmi.RMIServerImpl_Stub) which you can use to talk to JMX Agent (MBean Server) over RMI.

Hope this helps.

Prolancer
  • 71
  • 1
  • 2
  • Since you are stating that the answer by @david-tonhofer isn't correct, can you please explain how the URLs without the 1st IP:port pair (`192.168.30.10:1234` in this example) function? i.e., the URLs that start with `service:jmx:rmi:///jndi/rmi:`. Part of the reason this is so confusing in general is that when we specify a jmx port while starting the JVM, it doesn't reference RMI anywhere: `-Dcom.sun.management.jmxremote.port=2344`. (Note that in my experience that jmxremote port is associated with the "RMI Registry" portion of the URL, not the "JMX RMI Server" portion.) – erik.weathers Feb 01 '17 at 07:31
  • There are a number of ways to specify the IP and port that the JMX agent will use. If you wish to fix it to a specific IP and address you can use `service:jmx:rmi://192.168.30.10:1234`. Alternatively you can use `com.sun.management.—` properties. Use an URL such as `service:jmx:rmi:///…` to let Java pick the IP and port for you (randomly or based on system properties). Use an URL such as `service:jmx:rmi://0.0.0.0:1234` to bind port 1234 on all interfaces. And so on. Hope this helps. – Prolancer Aug 10 '18 at 00:09
4

According to javax.management.remote.rmi

this url is assembled like this

service:jmx:rmi://ignoredhost/jndi/rmi://myhost/myname
stacker
  • 64,199
  • 27
  • 132
  • 206