カスタム監視 Web アプリの Zookeeper インスタンス用の JMX Java クライアントをワークアウトしようとしています。ドキュメントで提供されているように、Zookeeper は JMX MBeans を介してさまざまな統計を提供します。
演習では、次の引数を使用して、Windows 7 Enterprise のスタンドアロン モードで Zookeeper インスタンスをローカルで実行しています。
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=10010
-Dzookeeper.jmx.log4j.disable=false
Zookeeper インスタンスを実行した後、すべての統計を正しく表示するJConsoleを使用して JMX Bean に接続できます:-
問題
自分のコードを使用して接続しようとすると、 java.net.ConnectException: Connection refused: connect
エラーが発生します。私が試しているコード:-
public static void main(String[] args) throws Exception {
// service:jmx:rmi:///jndi/rmi://#{host}:#{port}/jmxrmi
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:10010/jmxrmi");
// This throws java.net.ConnectException !!!
JMXConnector jmxConnector = JMXConnectorFactory.connect(url);
MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();
ObjectName mbeanName = new ObjectName("org.apache.ZooKeeperService:name0=StandaloneServer_port2181");
ZooKeeperServerMXBean newProxyInstance = MBeanServerInvocationHandler.newProxyInstance(mbeanServerConnection,
mbeanName, ZooKeeperServerMXBean.class, true);
System.out.println("Created zoo mbean proxy");
System.out.println(newProxyInstance.getAvgRequestLatency());
}
Java Visual VMを使用して接続しようとしているときに同じ問題に直面しています。
Java コードを使用して Zookeeper MBean に接続する正しい方法は何ですか?
更新 1
jmx ポートと rmi ポートの 2 種類のポートが関係していると思われる4 年前の未解決のJIRA チケットがあります。rmi ポートはランダムに生成されます。接続の作成中に必要だったと思います。
しかし、JConsole はどのように接続できるのでしょうか?
更新 2
このブログでは、RMI プロトコルを介してリモート JMX サーバーと通信すると問題が発生する可能性があり、代わりに JMXMP (JMX-Messaging Protocol) を使用することを提案しています。どうすれば正確にそれを行うことができますか?