Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have JMX bind to a specific interface?

Tags:

I am currently starting my Java VM with the com.sun.management.jmxremote.* properties so that I can connect to it via JConsole for management and monitoring. Unfortunately, it listens on all interfaces (IP addresses) on the machine.

In our environment, there are often cases where there is more than one Java VM running on a machine at the same time. While it's possible to tell JMX to listen on different TCP ports (using com.sun.management.jmxremote.port), it would be nice to instead have JMX use the standard JMX port and just bind to a specific IP address (rather than all of them).

This would make it much easier to figure out which VM we're connecting to via JConsole (since each VM effectively "owns" its own IP address). Has anyone figured out how to make JMX listen on a single IP address or hostname?

like image 664
Marc Novakowski Avatar asked Dec 01 '08 17:12

Marc Novakowski


People also ask

How do you expose a JMX port?

To open the JMX port on the remote JVM, you must enter the port number to use for the JMX RMI connection. Be sure to specify an unused port number. From a command line, go to the bin directory in the <JRE_HOME> directory that contains the Java Runtime Environment (JRE) implementation, for example jre/bin.

Is JMX a UDP or TCP port?

The JMX Messaging Protocol (JMXMP) connector is a configuration of the generic connector where the transport protocol is based on TCP and the object wrapping is native Java serialization.

How do I connect to local JMX?

In Java VisualVM's Applications window, right click on the Local machine and select 'Add JMX Connection'. The Add JMX Connection dialog box opens. The host name localhost is already filled in. You only need to add the port number on which the application is exposed for monitoring and management.


2 Answers

If anyone else will be losing his nerves with this ... After 10 years, they finally fixed it!

Since Java 8u102 -Dcom.sun.management.jmxremote.host binds to the selected IP

see: https://bugs.openjdk.java.net/browse/JDK-6425769

like image 144
Gašper Avatar answered Sep 30 '22 19:09

Gašper


Fernando already provided a link to my blog post :) ..it's not trivial. You have to provide your own RMIServerSocketFactoryImpl that creates sockets on the wanted address.

If internal/external interfaces are the problem and you have local access setting up a local firewall might be easier.

like image 35
tcurdt Avatar answered Sep 30 '22 17:09

tcurdt