Skip to content

Instantly share code, notes, and snippets.

@portante
Last active December 11, 2018 21:51
Show Gist options
  • Select an option

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

Select an option

Save portante/421b972d82deed3e596e6efb5fbccf5f to your computer and use it in GitHub Desktop.
Simple tool to interpret kibana logs under openshift via, "oc logs -c kibana <pod> | ./view-kibana-logs.py"
#!/usr/bin/env python
# oc logs -c kibana <pod> | ./view-kibana-logs.py
import sys
import json
import fileinput
lines = 0
valerrors = 0
successes = 0
keyerrors = 0
errors = 0
try:
for line in fileinput.input():
lines += 1
try:
doc = json.loads(line)
except ValueError as e:
print e, line[:-1]
valerrors += 1
continue
try:
if doc['statusCode'] in (200, 304):
successes += 1
continue
print doc['@timestamp'], doc['statusCode'], doc['message']
except KeyError:
keyerrors += 1
try:
print repr(doc.keys()), doc['@timestamp'], doc['message']
except KeyError:
errors += 1
print line[:-1]
except KeyboardInterrupt:
pass
finally:
pass
print lines, successes, valerrors, keyerrors, errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment