how to get current zookeeper cluster's member server list
Asked Answered
O

3

8

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.

Orna answered 21/5, 2013 at 11:39 Comment(0)
N
3

Zookeeper exposes this information over jmx.

Nainsook answered 26/5, 2013 at 1:47 Comment(3)
but I don't want to enable JMXOrna
I think you have to use jmx or one of the zookeeper four letter words, zookeeper.apache.org/doc/r3.1.2/…Nainsook
It seems that there is no other ways. Thanks.Orna
L
11

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.

Laboured answered 1/11, 2017 at 23:12 Comment(2)
or the new echo srvr | nc 127.0.0.1 2181Middleman
Yes, you could do this, but "srvr" just seems to omit the connected client information and is otherwise identical in output to the "stat" command I posted. Specifically, it still doesn't show you the quorum members or their statuses, which was the original question.Laboured
N
3

Zookeeper exposes this information over jmx.

Nainsook answered 26/5, 2013 at 1:47 Comment(3)
but I don't want to enable JMXOrna
I think you have to use jmx or one of the zookeeper four letter words, zookeeper.apache.org/doc/r3.1.2/…Nainsook
It seems that there is no other ways. Thanks.Orna
N
-2

It can also be query sending "stat" command using direct connection to port 2181.

For an example of how to do that from python see: https://github.com/apache/zookeeper/blob/765cedb5c65526384011ea958e59938fc7493168/src/contrib/huebrowser/zkui/src/zkui/stats.py

Novokuznetsk answered 17/8, 2016 at 22:50 Comment(1)
What if I don't like python?Forespeak

© 2022 - 2024 — McMap. All rights reserved.