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?
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With