Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to enable remote jmx monitoring programmatically?

I need to programmatically start a new java process and dynamically set the JMX port. So instead of doing this

-Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.port=9995 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

I would like to do the following

System.setProperty("java.rmi.server.hostname", "127.0.0.1" );
System.setProperty("com.sun.management.jmxremote", "true" );
System.setProperty("com.sun.management.jmxremote.authenticate", "false" );
System.setProperty("com.sun.management.jmxremote.ssl", "false" );
System.setProperty("com.sun.management.jmxremote.port", "9995"  );

but it doesn't work. Any idea why?

like image 812
Katerina A. Avatar asked Dec 16 '14 15:12

Katerina A.


People also ask

How do I enable JConsole for remote monitoring?

In your JConsole, select Remote Process and connect to the server and port that you've specified in your artifactory. default (or default) file. Authenticate this with the username/password specified in your jmxremote.

How do I enable JMX authentication?

To enable remote JMX connections, change the LOCAL_JMX setting in cassandra-env.sh. The default settings for Cassandra make JMX accessible only from localhost. If you want to enable remote JMX connections, change the LOCAL_JMX setting in cassandra-env.sh and enable authentication and/or ssl.


1 Answers

By the time your code is called you've missed your chance to configure the jmxremote connector.

What you need to do is create your own rmi registry and a JMXConnectorServer to listen for rmi calls and pass them to the MBeanServer.

private void createJmxConnectorServer() throws IOException {
    LocateRegistry.createRegistry(1234);
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:1234/jmxrmi");
    JMXConnectorServer svr = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    svr.start();
}
like image 55
AutomatedMike Avatar answered Sep 19 '22 10:09

AutomatedMike