Friday, March 28, 2008

Remote JMX, RMI, and JMXServiceURL

When using Remote JMX with RMI, one of the comma gotchas results from problems with the JMX connection server address string supplied to the JMX connector server and to the JMX connector client. This address string is encapsulated in the JMXServiceURL class and useful details about it are found in its Javadoc-generated documentation. This document tells us that JMXServiceURL represents an "address of a JMX API connector server" and that it needs to meet the format service:jmx:protocol:sap.

The Javadoc-generated documentation for the javax.management.remote package and for the javax.management.remote.rmi package are even more useful in understanding the substance of the JMX connector server address (JMXServiceURL).

The javax.management.remote package explains the JMX connector server address in greater detail and even offers an example of such an address for an RMI connector: service:jmx:rmi:///jndi/rmi://myhost:1099/myname where the emphasized text indicates your own host and port. This package's Javadoc description also informs us that the first rmi in the address specifies the RMI connector while the second rmi in the address specifies the RMI registry.

As you would expect, the Javadoc description for the RMI-specific package javax.management.remote.rmi has even more specific RMI details than does the more general javax.management.remote package. This documentation provides deep coverage of the many different ways that an RMI connection can be established and looked up.

I prefer to use a JMXServiceURL of the format service:jmx:rmi://<host>:<port>/jndi/rmi://<host>:<port>/jmxrmi or service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi for specifying my standard Remote JMX Connectors via RMI.

A nice pictorial representation of the JMX Connector Server address is available in the image at http://edong.net/2008v1/docs/jmx/jmx-proxy.png. This image shows which portion of the address makes up the RMI connector and which part makes up the RMI registry address. Monitor Your Applications with JConsole - Part 3 provides coverage of the connector server address using RMI. Chapter 9 ("Distributed Services and Connectors") of "JMX Accelerated Howto" covers the JMX Connector Server address in significant detail and provides several examples. The JMX Technology for Remote Management section of Getting Started with Java Management Extensions: Developing Management and Monitoring Solutions contains an example of using a JMX RMI Connector Server. Finally, the Remote Management lesson of the Java Management Extensions Trail of the Java Tutorials contains very useful background on using Remote JMX. The example code that comes with the JMX tutorial is especially useful.

11 comments:

Gunda said...

Hi,
Is jmx port is enable by default for websphere? or we have to enable it.
How can we enable the jmx port for websphere. where we have to configure?

its urgent pls help me as soon as possible.

Gunda said...

How can i get the jmx port for whebsphere?

@DustinMarx said...

Mallik,

I don't have much experience with WebSphere, but you might find the StackOverflow thread How Do You Enble JMX in WebSphere to be helpful.

Someone I never was said...

I need some urgent help on JMX and JConsole. While trying to connect to my application server using JConsole I use "localhost:8004". I have to write a JMX Client program which can connect to my application server. I tried doing that using JMXServiceURL and JMXConnectorFactory.connect(). But I am not been able to establish the connection.

How is JConsole actually creating the connection, in my case?

-Narita
narita.bagchi@headstrong.com

@DustinMarx said...

Narita,

JConsole provides the host:port syntax as a convenience, but also allows you to specify an entire JMX URL. The URL depends on the server. Check their documentation.

Dustin

@DustinMarx said...

Narita,

I should have also suggested that you check online forums related to your application server for JMX examples.

Dustin

Unknown said...

Hi;
How can I set the jndi name in my JMX Server?
(I want to change "jmxrmi")
Thanks.

Gunda said...

For JMX relate things

http://malliktalksjava.wordpress.com/category/java/jmx/

pomme said...

Hi Dustin, thanks for this useful post!
Could I have a question about the JMXServiceURL?

You showed two types of example of JMXServiceURL on RMI:
・service:jmx:rmi://:/jndi/rmi://:/jmxrmi
・service:jmx:rmi:///jndi/rmi://:/jmxrmi
and as for the former, I don't get how different the first : and the second :.
Could you let me know if these are supposed to be the same ones of different.

pomme said...

omg the String host and port are missing on my post somehow.
I meant:
・service:jmx:rmi://< host >:< port >/jndi/rmi://< host >:< port >/jmxrmi
・service:jmx:rmi:///jndi/rmi://< host >:< port >/jmxrmi

@DustinMarx said...

pom,

I have come to prefer the second (shorter) option and cannot think of a good reason why the first option would be preferable.

Dustin