Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get current zookeeper cluster's member server list

I want to get the member server list and their type(Leader or observer) in my java application. And also want to get the dead server.

Is their any way to do that? I read the document, but didn't find.

like image 646
Mavlarn Avatar asked May 21 '13 11:05

Mavlarn


2 Answers

It would be nice if there were a built-in answer for this without resorting to JMX. If you are on one of the zookeeper nodes, you can read the zoo.cfg file to get the list of servers (dead and alive ones) and then "stat" each one individually to see if it's alive and what its status is (note the "Mode" attribute on a successful response). E.g.:

$ echo stat | nc 127.0.0.1 2181
Zookeeper version: 3.4.5--1, built on 06/10/2013 17:26 GMT
Clients:
 /127.0.0.1:54752[1](queued=0,recved=215524,sent=215524)
 /127.0.0.1:59298[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/0/6
Received: 5596
Sent: 5596
Connections: 2
Outstanding: 0
Zxid: 0x10000010f
Mode: leader
Node count: 54

Note that "stat" does not show you the other members of the zookeeper ensemble--it only shows you the connected clients.

like image 135
King Rhoton Avatar answered Nov 12 '22 08:11

King Rhoton


Zookeeper exposes this information over jmx.

like image 3
sbridges Avatar answered Nov 12 '22 09:11

sbridges