Skip to content

Instantly share code, notes, and snippets.

@julbrs
Last active June 22, 2020 21:39
Show Gist options
  • Save julbrs/f18fd71bda2e1a26fde89da43870b659 to your computer and use it in GitHub Desktop.
Save julbrs/f18fd71bda2e1a26fde89da43870b659 to your computer and use it in GitHub Desktop.
360eyes log duration scanner
#!/usr/bin/env python
import re
import sys
from datetime import datetime
MIN_THRESHOLD = int(sys.argv[2])
regCompile = r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) .* FINE Opening .*: (\d*#.*)"
filePath = sys.argv[1]
lastTime = None
lastLine = ""
openDoc = 0
thresholdDoc = 0
with open(filePath, 'r') as f:
for line in f:
regexp = re.search(regCompile, line)
if regexp:
openDoc += 1
currentTime = datetime.strptime(re.search(regCompile, line).group(1), "%Y-%m-%d %H:%M:%S")
file = re.search(regCompile, line).group(2)
if lastTime != None:
duration = (currentTime - lastTime).seconds
if duration >= MIN_THRESHOLD:
print ("% ds\t% s" % (duration, file))
thresholdDoc += 1
lastTime = currentTime
lastLine = line
f.closed
print ("% d doc opened" % openDoc)
print ("% d doc over threshold" % thresholdDoc)

Log Duration 360eyes scanner

Run it like that :

./log_duration.py WEBI_20200623_102345_BOBJ_SERVER.log 10

And it will output the document that take the more time (more than 10 seconds) :

 22s	234#/Root Folder/Folder A/Report_A (type:PUBLIC)
 12s	2355#/Root Folder/Folder B/Report_B (type:PUBLIC)
 251 doc opened
 2 doc over threshold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment