79127220

Date: 2024-10-25 20:23:46
Score: 2
Natty:
Report link

Based on Is it possible to enable remote jmx monitoring programmatically?

I was able to give an answer to this: https://stackoverflow.com/a/79126986/17205238

TLDR; Register a Bean and manually startup the JMX rmi connector pass environment variables as needed (https://docs.oracle.com/javase/8/docs/technotes/guides/jmx/tutorial/security.html in my example via the method getJmxEnvironment())

    @Bean
    Registry rmiRegistry() throws Exception {
        
        var jmxPort = getJmxPort(); //get your port from a property? jmx.port
        var registry = LocateRegistry.createRegistry(jmxPort);
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://0.0.0.0:"+jmxPort+"/jndi/rmi://127.0.0.1:"+jmxPort+"/jmxrmi");
        JMXConnectorServer srvr = JMXConnectorServerFactory.newJMXConnectorServer(url, getJmxEnvironment(), mbs);
        srvr.start();
        return registry;
    }

Hope it helps

Reasons:
  • Blacklisted phrase (1): Is it possible to
  • Blacklisted phrase (1): stackoverflow
  • Whitelisted phrase (-1): Hope it helps
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: manrodriguezf