Created
April 10, 2017 15:54
-
-
Save portante/af50b6f37333049153e98a6dfa102ade to your computer and use it in GitHub Desktop.
Simple python script to merge logs from kibana
This file contains hidden or 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 os, sys, json | |
| lines = [] | |
| for fn in sys.argv[1:]: | |
| with open(fn, "r") as fp: | |
| line_count = 0 | |
| for line in fp.readlines(): | |
| line_doc = json.loads(line) | |
| line_doc['__file__'] = fn | |
| lines.append(line_doc) | |
| line_count += 1 | |
| print("File: %s, lines: %d" % (fn, line_count)) | |
| lines_sorted = sorted(lines, key=lambda k: k['@timestamp']) | |
| for line in lines_sorted: | |
| if line['type'] == 'response': | |
| print("%(@timestamp)s %(__file__)s %(type)s %(method)s %(statusCode)s %(message)s" % line) | |
| else: | |
| print("%(@timestamp)s %(__file__)s %(type)s %(message)s" % line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment