Skip to content

Instantly share code, notes, and snippets.

@portante
Created April 10, 2017 15:54
Show Gist options
  • Select an option

  • Save portante/af50b6f37333049153e98a6dfa102ade to your computer and use it in GitHub Desktop.

Select an option

Save portante/af50b6f37333049153e98a6dfa102ade to your computer and use it in GitHub Desktop.
Simple python script to merge logs from kibana
#!/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