-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.py
29 lines (26 loc) · 899 Bytes
/
parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import re
import fileinput
from urlparse import parse_qs
RE = re.compile("INFO - (?P<timestamp>.*);"
" .*; \[(?P<collection>.*)\] webapp=.*"
" path=/select params=\{(?P<params>.*)\}"
" hits=(?P<hits>\d+) status=.*"
" QTime=(?P<query_milliseconds>\d+)")
for line in fileinput.input():
match = RE.match(line)
if match:
groups = match.groupdict()
params = parse_qs(groups['params'])
try:
print '\t'.join( (
groups['timestamp'],
groups['collection'],
params.get('q', [''])[0],
params.get('start', ['0'])[0],
params.get('rows', ['\N'])[0],
groups['hits'],
groups['query_milliseconds'],
) )
except:
print 'offending line: ' + line
raise