Skip to content

Instantly share code, notes, and snippets.

@joestein
Created August 5, 2014 20:00
Show Gist options
  • Save joestein/07ebc9adbfaa624acfc9 to your computer and use it in GitHub Desktop.
Save joestein/07ebc9adbfaa624acfc9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
nodesLeadingPartitions = {}
nodesLeadingPartitionsForTopic = {}
currentTopicName = ""
for line in sys.stdin:
# try:
line = line.strip()
l = line.split(" ")
if "PartitionCount" in line:
#we are on a new topic
currentTopicName = l[0].replace("Topic:","")
print "topic = %s" % currentTopicName
else :
#have we seen this leader?
leaderName = line.split("Leader:")[1].split("Replicas:")[0]
#print "leader = %s" % leaderName
if leaderName in nodesLeadingPartitions:
nodesLeadingPartitions[leaderName] = nodesLeadingPartitions[leaderName] + 1
else:
nodesLeadingPartitions[leaderName] = 1
#print "nodesLeadingPartitionsForTopic=%s" % nodesLeadingPartitionsForTopic
if currentTopicName in nodesLeadingPartitionsForTopic:
#print "nodesLeadingPartitionsForTopic[currentTopicName] = %s" % nodesLeadingPartitionsForTopic[currentTopicName]
leaderMap = {}
leaderMap = nodesLeadingPartitionsForTopic[currentTopicName]
if leaderName in leaderMap:
leaderMap[leaderName] = leaderMap[leaderName] + 1
else:
leaderMap[leaderName] = 1
nodesLeadingPartitionsForTopic[currentTopicName] = leaderMap
else:
leaderMap = {}
leaderMap[leaderName] = 1
nodesLeadingPartitionsForTopic[currentTopicName] = leaderMap
print "nodes that are leaders"
for k,v in nodesLeadingPartitions.iteritems():
print " %s = %s" % (k,v)
for k,v in nodesLeadingPartitionsForTopic.iteritems():
print "topic = %s" % k
for kp, vp, in v.iteritems():
print " leader node %s = %s" % (kp,vp)
# except:
# pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment