Last active
December 22, 2015 21:23
-
-
Save ottomata/f67e25f8c57b3c20cebd to your computer and use it in GitHub Desktop.
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
# export PYTHONPATH=/srv/deployment/eventlogging/eventlogging | |
## https://github.com/jsocol/pystatsd/issues/24 | |
# export DJANGO_SETTINGS_MODULE="DO NOT USE" | |
# | |
# python count_field.py <topic> <field> | |
# | |
from eventlogging import get_reader | |
import argparse | |
from pprint import pprint | |
ap = argparse.ArgumentParser() | |
ap.add_argument('topic') | |
ap.add_argument('field') | |
args = ap.parse_args() | |
kafka_uri = 'kafka:///kafka1012.eqiad.wmnet:9092?zookeeper_connect=conf1001.eqiad.wmnet:2181/kafka/eqiad&topic=%s' % args.topic | |
counts = {} | |
for e in get_reader(kafka_uri): | |
if args.field in e['event']: | |
value = e['event'][args.field] | |
count = counts.setdefault(value, 0) | |
counts[value] += 1 | |
pprint(counts) |
Author
ottomata
commented
Dec 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment