Created
August 28, 2015 16:16
-
-
Save ConnorDoyle/10e7c9c9bc17e074558c to your computer and use it in GitHub Desktop.
libprocess_queues.py
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 httplib | |
import json | |
import prettytable | |
import sys | |
def fetch_list(master): | |
con = httplib.HTTPConnection(master) | |
con.request("GET", "/__processes__") | |
return json.loads(con.getresponse().read()) | |
def get_counts(data): | |
def acc_names(acc, x): | |
if not "name" in x: | |
return acc | |
acc[x["name"]] = acc.get(x["name"], 0) + 1 | |
return acc | |
for actor in data: | |
yield [actor["id"], '', len(actor["events"])] | |
for k,v in reduce(acc_names, actor["events"], {}).iteritems(): | |
yield [actor["id"], k, v] | |
def run(host): | |
tb = prettytable.PrettyTable( | |
["Actor", "Event", "Count"], | |
border=False, | |
max_table_width=80, | |
hrules=prettytable.NONE, | |
vrules=prettytable.NONE, | |
left_padding_width=0, | |
right_padding_width=1 | |
) | |
for line in get_counts(fetch_list(host)): | |
tb.add_row(line) | |
print tb | |
if __name__ == "__main__": | |
run(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment