Last active
November 10, 2021 06:03
-
-
Save asdaraujo/9b84b02d663ec3fda38156f8d3709f95 to your computer and use it in GitHub Desktop.
sqlio_log_parser.py
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
import os | |
import re | |
import sys | |
import subprocess | |
import time | |
from subprocess import Popen, PIPE | |
def ps(pid): | |
p = Popen('ps -ef | grep {}'.format(pid), shell=True, stdout=PIPE, stderr=PIPE) | |
stdout, _ = p.communicate() | |
print(stdout.decode()) | |
def follow(thefile): | |
# seek the end of the file | |
thefile.seek(0, os.SEEK_END) | |
# start infinite loop | |
while True: | |
# read last line of file | |
line = thefile.readline() | |
# sleep if file hasn't been updated | |
if not line: | |
time.sleep(0.1) | |
continue | |
yield line | |
filein = open(sys.argv[1], 'r') | |
for line in follow(filein): | |
m = re.match(r'^.*replication slot .* is active for PID ([0-9]+)', line) | |
if m: | |
print("===================== PS ======================") | |
ps(m.groups()[0]) | |
m = re.match(r'^.*"stack-trace":"(.*)","serialized-throwable"', line) | |
if m: | |
print(m.groups()[0].replace(r'\n', '\n').replace(r'\t', '\t')) | |
continue | |
if 'Unable to obtain Principal Name for authentication' in line: | |
continue | |
if re.match(r'^[ \t]*(Caused by|at |.*Exception)', line): | |
print(line.rstrip()) | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment