Skip to content

Instantly share code, notes, and snippets.

@1stvamp
Last active June 22, 2017 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1stvamp/431d990c37ad9f1fd270aaa08132c2ef to your computer and use it in GitHub Desktop.
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.
#!/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