是否可以通过编程方式启用远程jmx监控? [英] Is it possible to enable remote jmx monitoring programmatically?

查看:169
本文介绍了是否可以通过编程方式启用远程jmx监控?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式启动一个新的java进程并动态设置JMX端口。
所以不要这样做

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

我想执行以下操作

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?

推荐答案

当您的代码被调用时,您错过了配置jmxremote连接器的机会。

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

您需要做的是创建自己的rmi注册表和JMXConnectorServer以侦听rmi调用并将它们传递给MBeanServer。

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();
}

这篇关于是否可以通过编程方式启用远程jmx监控?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆