Skip to content

Instantly share code, notes, and snippets.

@ranjib
Created September 11, 2013 22:55
Show Gist options
  • Save ranjib/6530906 to your computer and use it in GitHub Desktop.
Save ranjib/6530906 to your computer and use it in GitHub Desktop.
Check Zookeeper
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