You can determine which node is acting as a leader by enter the following command:
echo stat | nc localhost 2181 | grep Mode
You will get the response if the node is acting as a leader:
Mode: leader
If it is a follower, you will see:
Mode: follower
Alternatively, you can use the zkServer.sh located in /opt/zookeeper/bin:
./zkServer.sh status
The output of which would be:
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Mode: follower
You can obtain even more information using:
echo mntr | nc localhost 2181
The output of which is:
zk_version 3.4.8--1, built on 02/06/2016 03:18 GMT
zk_avg_latency 0
zk_max_latency 0
zk_min_latency 0
zk_packets_received 7
zk_packets_sent 6
zk_num_alive_connections 2
zk_outstanding_requests 0
zk_server_state follower
zk_znode_count 357
zk_watch_count 0
zk_ephemerals_count 5
zk_approximate_data_size 846524
zk_open_file_descriptor_count 36
zk_max_file_descriptor_count 4096
If the node is a leader, you will also see:
zk_followers 5
zk_synced_followers 5
zk_pending_syncs 0
The following will not be present on Windows platforms:
zk_open_file_descriptor_count 43
zk_max_file_descriptor_count 4096
Using the information above, you can determine the health of your Zookeeper ensemble.