Last active
August 29, 2015 14:01
-
-
Save atdt/8deed4bc2d311ba0122f to your computer and use it in GitHub Desktop.
Print current EventLogging traffic
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import division | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf8') | |
import collections | |
import itertools | |
import operator | |
import signal | |
import zmq | |
DURATION = 60 | |
ctx = zmq.Context.instance() | |
sock = ctx.socket(zmq.SUB) | |
sock.connect('tcp://vanadium.eqiad.wmnet:8600') | |
sock.setsockopt(zmq.SUBSCRIBE, b'') | |
sock.linger = 0 | |
stream = iter(sock.recv_json, '') | |
counter = collections.Counter() | |
def display_breakdown(signum, frame): | |
total = sum(counter.values()) | |
seen = sorted(counter.iteritems(), None, operator.itemgetter(1), True) | |
for schema, count in seen: | |
rate = count / DURATION | |
portion = count / total | |
print '{0:<50}{1:.2%} ({2:.2f}/sec)'.format(schema, portion, rate) | |
print 'Overall: {0:.2f} events / sec.'.format(total / 60) | |
signal.alarm(DURATION) | |
signal.signal(signal.SIGALRM, display_breakdown) | |
print 'Listening for {:d} seconds...'.format(DURATION) | |
try: | |
counter = counter.update(event['schema'] for event in stream) | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment