Created a simple logfile evaluation script to look at bad dbh response times

This commit is contained in:
Daniel Schick 2024-03-12 08:12:15 +01:00
parent 8482ebfd12
commit 1454f80191
2 changed files with 65 additions and 0 deletions

3
LogFileEvaluation/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*txt*
*.csv
*.xlsx

View File

@ -0,0 +1,62 @@
import os
import datetime
from collections import deque
# open numbered log files and evaluate the results
# the log files have been copied from the server to this directory
# the log files are named log-NSWMessageService.txt.0, log-NSWMessageService.txt.1, log-NSWMessageService.txt.2, ...
# for the first analysis I have copied 10 log files to this directory but placed them in the .gitignore file
# get the current working directory
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
outputFileName = dname + "\\" + 'output.csv'
# open the output file
outputFile = open(outputFileName, 'w')
# write the header
outputFile.write('Receive time, Duration\n')
# open the log files
q = deque()
for i in range(0, 10):
logFileName = dname + "\\" + 'log-NSWMessageService.txt.' + str(i)
logFile = open(logFileName, 'r')
# read the content line by line
while True:
line = logFile.readline()
if not line:
break
# get substring of the date
dateString = line[0:19]
if "Upload of" in line:
# add the dateString to the queue
q.appendleft(dateString)
elif "Download of" in line:
# find the corresponding dateString in the queue
# calculate the duration
# remove the dateString from the queue
lastdatestring = q.pop()
# create date from string
lastdate = datetime.datetime.strptime(lastdatestring, '%Y-%m-%d %H:%M:%S')
currentdate = datetime.datetime.strptime(dateString, '%Y-%m-%d %H:%M:%S')
# calculate the duration
duration = currentdate - lastdate
outputFile.write(dateString + "," + str(duration.seconds) + "\n")
# close the log file
logFile.close()
outputFile.close()