2019-04-27 18:05:00 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import csv
|
2019-04-30 15:44:00 +02:00
|
|
|
import os
|
2019-04-30 15:56:21 +02:00
|
|
|
from pprint import pprint
|
2019-04-30 15:44:00 +02:00
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
2019-04-27 18:05:00 +02:00
|
|
|
|
2019-04-30 15:44:00 +02:00
|
|
|
#Returns array of csv files in current directory
|
|
|
|
def getFiles():
|
|
|
|
files = [f for f in os.listdir('.') if os.path.isfile(f)]
|
|
|
|
return[ f for f in files if f.endswith('.csv') ]
|
2019-04-27 18:05:00 +02:00
|
|
|
|
2019-04-30 15:44:00 +02:00
|
|
|
def processFile(fname):
|
2019-04-30 15:56:21 +02:00
|
|
|
with open(fname,'r') as f:
|
2019-04-30 15:44:00 +02:00
|
|
|
lines=[]
|
|
|
|
data=csv.reader(f)
|
2019-04-30 15:56:21 +02:00
|
|
|
fields=next(data)
|
2019-04-30 22:59:18 +02:00
|
|
|
responseCodes={}
|
|
|
|
responsePerSec={}
|
|
|
|
responseTimes=[]
|
2019-04-30 15:44:00 +02:00
|
|
|
for row in data:
|
|
|
|
items=zip(fields,row)
|
|
|
|
item={}
|
|
|
|
for(name,value) in items:
|
|
|
|
item[name]=value.strip()
|
2019-04-30 22:59:18 +02:00
|
|
|
sec=int(item['offset'].split('.')[0])
|
|
|
|
if sec not in responsePerSec:
|
2019-05-02 12:55:42 +02:00
|
|
|
responsePerSec[sec]=[]
|
2019-04-30 22:59:18 +02:00
|
|
|
else:
|
2019-05-02 12:55:42 +02:00
|
|
|
responsePerSec[sec].append(item['response-time'])
|
2019-04-30 22:59:18 +02:00
|
|
|
code=item['status-code']
|
|
|
|
if code not in responseCodes:
|
|
|
|
responseCodes[code]=1
|
|
|
|
else:
|
|
|
|
responseCodes[code]=responseCodes[code]+1
|
|
|
|
responseTimes.append(item['response-time'])
|
2019-05-06 18:53:37 +02:00
|
|
|
if len(responseTimes)!=0:
|
|
|
|
maxResponse=max(responseTimes)
|
|
|
|
minResponse=min(responseTimes)
|
2019-04-30 22:59:18 +02:00
|
|
|
print("Maximum response time was ",maxResponse)
|
|
|
|
print("Minimum response time was ",minResponse)
|
2019-05-06 18:53:37 +02:00
|
|
|
else:
|
|
|
|
print("csv is empty")
|
2019-04-30 22:59:18 +02:00
|
|
|
pprint(responseCodes)
|
2019-05-02 12:55:42 +02:00
|
|
|
for sec in responsePerSec:
|
2019-05-06 18:53:37 +02:00
|
|
|
if len(responsePerSec[sec])!=0:
|
|
|
|
print(sec, ":")
|
|
|
|
print(" Maximum:", max(responsePerSec[sec]))
|
|
|
|
print(" Minimum:", min(responsePerSec[sec]))
|
|
|
|
print(" Num of responses:", len(responsePerSec[sec]))
|
|
|
|
else:
|
|
|
|
print(" empty")
|
2019-04-30 23:00:39 +02:00
|
|
|
|
2019-04-30 15:44:00 +02:00
|
|
|
def processAllFiles():
|
|
|
|
files=getFiles()
|
|
|
|
for f in files:
|
2019-04-30 15:56:21 +02:00
|
|
|
print("Processing ", f)
|
2019-04-30 22:59:18 +02:00
|
|
|
processFile(f)
|
2019-04-27 18:05:00 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-04-30 15:44:00 +02:00
|
|
|
processAllFiles()
|