Is it possible to programmatically monitor jmx remotely?

I need to programmatically start a new java process and dynamically set the JMX port. Therefore instead

-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 that will not work. Any idea why?

+6
source share
1 answer

By the time of your code, you missed your chance to configure the jmxremote connector.

What you need to do is create your own rmi registry and JMXConnectorServer to listen for rmi calls and transfer them to 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(); } 
+9
source

Source: https://habr.com/ru/post/979706/


All Articles