Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using a JMX server with ephemeral port, how to get the server port number?

Tags:

java

jmx

rmi

mbeans

When launching a Java application with these options:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=0
-Dcom.sun.management.jmxremote.local.only=false

Java uses an ephemeral port, which is very useful to avoid collisions.

Is it possible to get the actual port (or connection URL) programmatically from within the application ?

like image 628
nicoulaj Avatar asked Sep 06 '16 08:09

nicoulaj


People also ask

What is the JMX port number?

The default port for secure JMX access is 9875 and the default username and password are admin and springsource .

What is JMX RMI port?

com.sun.management.jmxremote.port. Enables the JMX remote agent and creates a remote JMX connector to listen through the specified port. By default, the SSL, password, and access file properties are used for this connector.


1 Answers

    String url = sun.management.ConnectorAddressLink.importRemoteFrom(0)
            .get("sun.management.JMXConnectorServer.0.remoteAddress");
    System.out.println(url);

This will print URL like

service:jmx:rmi:///jndi/rmi://hostname:57025/jmxrmi
like image 112
apangin Avatar answered Sep 30 '22 10:09

apangin