python脚本之统计log的请求时间
1 #!/usr/bin/python 2 # -*- coding:UTF-8 -*- 3 import os 4 import datatime 5 import time 6 import sys 7 import shutil 8 9 10 resulitFile='C:/……/file.txt' 11 12 def resultE2ETime(): 13 dataTime=[] 14 with open(resulitFile,'r') as f: 15 for line in f : 16 if '******' in line: 17 data = line.split("|")[6] 18 dataTime.append(float(data)) 19 20 dataTimeAll = sorted(dataTime) 21 print("所有时间集合为====" + str(dataTimeAll)) 22 lenAll = len(dataTimeAll) 23 print("所有时间长度为====" + str(lenAll) + "个") 24 len50 = len(dataTimeAll) * 0.5 25 len90 = len(dataTimeAll) * 0.9 26 len95 = len(dataTimeAll) * 0.95 27 len99 = len(dataTimeAll) * 0.99 28 len9999 = len(dataTimeAll) * 0.9999 29 count = 0 30 dataTimeout = [] 31 for i in dataTimeAll: 32 if i >=300.0: 33 count = count +1 34 35 dataTimeout.append(float(i)) 36 37 print(dataTimeout) 38 print("P50的responseTime值为====" + str(dataTimeAll[int(len50)])) 39 print("P90的responseTime值为====" + str(dataTimeAll[int(len90)])) 40 print("P95的responseTime值为====" + str(dataTimeAll[int(len95)])) 41 print("P99的responseTime值为====" + str(dataTimeAll[int(len99)])) 42 print("P9999的responseTime值为====" + str(dataTimeAll[int(len9999)])) 43 print("超过300ms的responseTime数量为====" + str(count)) 44 print("所有请求数量为====" + str(lenAll) + "个") 45 46 47 if __name__ =='__main__': 48 resultE2ETime()