Last active
June 22, 2017 09:37
-
-
Save 1stvamp/431d990c37ad9f1fd270aaa08132c2ef to your computer and use it in GitHub Desktop.
Crappy script to parse a honcho log and get a sorted list of services that took the longest time before serving a request.
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 | |
import dateutil.parser | |
import operator | |
import pprint | |
import sys | |
with open(sys.argv[1]) as f: | |
log = f.readlines() | |
last_times = {} | |
items = {} | |
for l in log: | |
if 'HTTP/1.1' in l: | |
continue | |
l = l.strip() | |
if l.count('|') < 3: | |
l += ('|' * (3 - l.count('|'))) | |
parts, cmd, _, _ = l.split('|') | |
time, service = parts.strip().split(' ') | |
time = dateutil.parser.parse(time) | |
if service not in last_times: | |
items[service] = 0.0 | |
else: | |
last = last_times[service] | |
if time == last: | |
continue | |
items[service] += (time - last).seconds | |
last_times[service] = time | |
pprint.pprint(sorted(items.items(), reverse=True, key=operator.itemgetter(1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment