Created
September 11, 2013 22:55
-
-
Save ranjib/6530906 to your computer and use it in GitHub Desktop.
Check Zookeeper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import telnetlib | |
import re | |
hosts = [ 'zk06.pd-internal.com', 'zk07.pd-internal.com', 'zk08.pd-internal.com', | |
'zk10.pd-internal.com', 'zk11.pd-internal.com' ] | |
leaders = {} | |
followers = {} | |
standalone = {} | |
for host in hosts: | |
tn = telnetlib.Telnet(host, 2181) | |
tn.write("stats\n") | |
output = tn.read_all() | |
mode = filter(lambda s:re.search(r'Mode: ',s) , output.split("\n"))[0] | |
if re.search(r'follower', mode): | |
followers[host] = (output) | |
elif re.search(r'leader', mode): | |
leaders[host] = (output) | |
else: | |
standalone[host] = (output) | |
leader_count = len(leaders.keys()) | |
standalone_count = len(standalone.keys()) | |
if leader_count != 1 : | |
raise Exception("Number of leader is: " % leader_count) | |
elif standalone_count > 0 : | |
raise Exception("Number of standalone node:" % standalone_count) | |
else: | |
print "All is well" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment