Created
October 6, 2014 17:21
-
-
Save phobos182/33f07871e48d7c6ec7d4 to your computer and use it in GitHub Desktop.
ZooKeeper zkTraffic report viewer.
This file contains hidden or 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
#!/usr/bin/env python | |
import argparse | |
import brood | |
import requests | |
ENDPOINT_ADDR = '127.0.0.1' | |
ENDPOINT_PORT = 7070 | |
TOP_ITEMS = 10 | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--top-ip', action='store_true', default=False, help='top ip addresses report') | |
parser.add_argument('--top-path', action='store_true', default=False, help='top path changed report') | |
args = parser.parse_args() | |
cmdb = brood.Brood() | |
top_talkers = [] | |
if args.top_ip: | |
result = requests.get('http://{}:{}/json/ips'.format(ENDPOINT_ADDR, ENDPOINT_PORT)).json() | |
else: | |
result = requests.get('http://{}:{}/json/paths'.format(ENDPOINT_ADDR, ENDPOINT_PORT)).json() | |
for key, val in result.iteritems(): | |
if args.top_ip: | |
if key.startswith('per_ip/ConnectRequest'): | |
ip_address = key.split(':')[1] | |
hostname = cmdb.get_query(query='config.internal_address:{}'.format(ip_address), fields='config.name')[0]['config.name'] | |
top_talkers.append({'key': hostname, 'value': val}) | |
else: | |
if key.startswith('NodeChildrenChanged'): | |
path_changed = '/'.join(key.split(':')[0].split('/')[1:]) | |
top_talkers.append({'key': path_changed, 'value': val}) | |
top_talkers = sorted(top_talkers, key=lambda k: k['value'], reverse=True) | |
for _ in xrange(0, TOP_ITEMS): | |
try: | |
print 'key: {}, value: {}'.format(top_talkers[_]['key'], top_talkers[_]['value']) | |
except Exception: | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment