Created
March 27, 2018 20:33
-
-
Save gmambro/fa6859b62328ccdc85f9ae4c46f43cf3 to your computer and use it in GitHub Desktop.
Zookeeper stats snippet
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 socket | |
host = '127.0.0.1' | |
port = 2181 | |
facts = {} | |
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
client.connect((host, port)) | |
f = client.makefile() | |
f.write('stat') | |
f.flush() | |
for line in f: | |
line = line.strip() | |
#Receiving from client | |
print line | |
k,v = line.split(':', 1) | |
if k == 'Zookeeper version': | |
facts['version'] = v | |
elif k == 'Clients': | |
clients = [] | |
line2 = f.readline().strip() | |
while line2 != '': | |
print "* %s *" % line2 | |
clients.append(line2) | |
line2 = f.readline().strip() | |
elif k == 'Latency min/avg/max': | |
values = v.split('/') | |
facts['latency'] = { 'min': values[0], 'avg': values[1], 'max': values[2] } | |
elif k in [ 'Received', 'Sent', 'Connections', 'Outstanding', 'Zxid', 'Mode', 'Node count' ]: | |
facts[k.lower()] = v | |
client.close() | |
print facts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment