2

I am trying to workout a JMX Java client for Zookeeper instance for a custom monitoring web app. As provided in document, Zookeeper provides various statistics through JMX MBeans.

For the excercise, I am running Zookeeper intance locally in standalone mode on Windows 7 Enterprise using following arguments:-

-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

After running my zookeeper intance, I am able to connect to JMX beans using JConsole that correctly shows all the statistics :-

Jconsole screen

PROBLEM

While trying to connect using my own code I am getting java.net.ConnectException: Connection refused: connect error. Code that I am trying :-

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

}

Facing same problem while trying to connect using Java Visual VM.

What is the correct way to connect to Zookeeper MBean using Java code ?

UPDATE 1

There is 4 years old unresolved JIRA ticket that seems to be saying that there are two kind of ports that comes into play - jmx port & rmi port. The rmi port is generated randomly & I guess that is what needed while creating connection.

But then how JConsole is able to connect ?

UPDATE 2

This blog says that talking to remote JMX server over RMI protocol might be problem and suggests using JMXMP (JMX-Messaging Protocol) instead. Now how do I exactly do I do that ?

Kumar Sambhav
  • 7,503
  • 15
  • 63
  • 86
  • What kind of metrics are you trying to obtain? Isn't this exactly what [exhibitor](https://github.com/soabase/exhibitor) is supposed to do? – Tombart Nov 29 '16 at 14:28
  • @Tombart - yes. But we are not sure of using it due to many reasons - 1. We already have a web based monitoring/admin app and prefer to just plugin ZK administration there itself. 2. Exhibitor gihub page says - 'Exhibitor is now on its own! '. Looks like it is not that actively supported/maintaned now. 3. https://github.com/soabase/exhibitor/issues/317 4. The Exhibitor UI doesn't look appealing - to me at least. We are looking for UI/UX that's consistent with our existing. – Kumar Sambhav Nov 30 '16 at 06:43
  • @Tombart - Metrics/Functionality that I want - ZK ensemble info, for each ensemble member data points as mentioned in screenshot, ability to reset statistics/latency, change tick time. – Kumar Sambhav Nov 30 '16 at 07:11
  • 1
    Most monitoring plugins use [the 4 letter commands](https://zookeeper.apache.org/doc/trunk/zookeeperAdmin.html#The+Four+Letter+Words) to fetch statistics `echo mntr | nc localhost 2181`. Yeah, great opportunity to improve Exhibitor without reinventing the wheel. – Tombart Nov 30 '16 at 09:30
  • @Tombart - Yeah. I am switching back to using the 4 letter commands ( parsing their response is pain though). The doc says that 3.5 will come with embedded jetty that will expose endpoint to execute 4LC. Hoping the response will be json that might ease the parsing part. – Kumar Sambhav Nov 30 '16 at 12:34
  • https://zookeeper.apache.org/doc/trunk/zookeeperAdmin.html#sc_adminserver – Kumar Sambhav Nov 30 '16 at 13:15

0 Answers0