Created
May 27, 2013 07:17
-
-
Save bdargan/5655606 to your computer and use it in GitHub Desktop.
slow search log parser for es
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 sys, re, json | |
from collections import defaultdict, namedtuple | |
# with jaysw | |
#Slow Search Log | |
#[2013-05-27 07:04:44,833][WARN ][index.search.slowlog.fetch] [local1] [idx2][2] took[1s], took_millis[1043], types[property], stats[], search_type[QUERY_THEN_FETCH], | |
#Slow Index Log, currently not supported | |
#[2013-05-27 08:32:23,397][TRACE][index.indexing.slowlog.index] [local1] [idx2][0] took[607.8ms], took_millis[607], type[offer], id[2b13a5e5d5029f7b3609c9ddb89a7419] | |
# cat samples/slow-search.log| python ./esslow | jq -c '.' | |
pat = re.compile( | |
r'^\[(?P<time>(.*?))\]' | |
r'\[(?P<level>\S+?)\s+\]' | |
r'\[(?P<file>\S+?)\]' | |
r'\s\[(?P<host>.+?)\]' | |
r'\s\[(?P<index>.+?)\]' | |
r'\[(?P<shard>.+?)\]' | |
r'\stook\[(?P<took>.+?)\]' | |
r',\stook_millis\[(?P<took_millis>.+?)\]' | |
r',\stypes\[(?P<types>.+?)\]' | |
r',\sstats\[(?P<stats>.*?)\]' | |
r',\ssearch_type\[(?P<search_type>.*?)\]' | |
) | |
def process(input): | |
for line in input: | |
m = re.search(pat, line) | |
if m: | |
print json.dumps(m.groupdict()) | |
if __name__ == '__main__': | |
process(sys.stdin) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment