Jmeter Summariser report及其可視化


Jmeter summariser report的設置在:bin/jmeter.properties

#---------------------------------------------------------------------------
# Summariser - Generate Summary Results - configuration (mainly applies to non-GUI mode)
#---------------------------------------------------------------------------
#
# Define the following property to automatically start a summariser with that name
# (applies to non-GUI mode only)
summariser.name=summary
#
# interval between summaries (in seconds) default 3 minutes
summariser.interval=180
#
# Write messages to log file
summariser.log=true
#
# Write messages to System.out
#summariser.out=true

以上設置每隔3分鍾向jmeter.log中寫入一行log
# Combined log file (for jmeter and jorphan)
log_file=jmeter.log

log的格式如下:

2017-11-21 15:49:14,389 INFO o.a.j.t.JMeterThread: Thread started: 線程組 1-100
2017-11-21 15:49:14,392 INFO o.a.j.p.h.s.HTTPHC4Impl: HTTP request retry count = 0
2017-11-21 15:49:14,408 INFO o.a.j.s.SampleResult: Note: Sample TimeStamps are START times
2017-11-21 15:49:14,411 INFO o.a.j.s.SampleResult: sampleresult.default.encoding is set to ISO-8859-1
2017-11-21 15:49:14,411 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true
2017-11-21 15:49:14,411 INFO o.a.j.s.SampleResult: sampleresult.nanoThreadSleep=5000
2017-11-21 15:49:30,006 INFO o.a.j.r.Summariser: summary + 4857 in 00:00:16 = 308.1/s Avg: 258 Min: 22 Max: 7941 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
2017-11-21 15:50:00,002 INFO o.a.j.r.Summariser: summary +  11529 in 00:00:30 =  384.3/s Avg:   271 Min:    30 Max: 21225 Err:     0 (0.00%) Active: 100 Started: 100 Finished: 0
2017-11-21 15:50:00,003 INFO o.a.j.r.Summariser: summary =  16386 in 00:00:46 =  358.1/s Avg:   267 Min:    22 Max: 21225 Err:     0 (0.00%)
2017-11-21 15:50:30,004 INFO o.a.j.r.Summariser: summary +  12104 in 00:00:30 =  403.5/s Avg:   233 Min:    43 Max: 15109 Err:    31 (0.26%) Active: 100 Started: 100 Finished: 0
2017-11-21 15:50:30,005 INFO o.a.j.r.Summariser: summary =  28490 in 00:01:16 =  376.0/s Avg:   252 Min:    22 Max: 21225 Err:    31 (0.11%)
2017-11-21 15:51:00,002 INFO o.a.j.r.Summariser: summary +  12112 in 00:00:30 =  403.8/s Avg:   268 Min:    44 Max: 84469 Err:    51 (0.42%) Active: 100 Started: 100 Finished: 0
2017-11-21 15:51:00,003 INFO o.a.j.r.Summariser: summary =  40602 in 00:01:46 =  383.9/s Avg:   257 Min:    22 Max: 84469 Err:    82 (0.20%)
2017-11-21 15:51:30,017 INFO o.a.j.r.Summariser: summary +  11994 in 00:00:30 =  399.6/s Avg:   245 Min:    40 Max: 17814 Err:    42 (0.35%) Active: 100 Started: 100 Finished: 0
2017-11-21 15:51:30,018 INFO o.a.j.r.Summariser: summary =  52596 in 00:02:16 =  387.4/s Avg:   254 Min:    22 Max: 84469 Err:   124 (0.24%)
2017-11-21 15:52:00,003 INFO o.a.j.r.Summariser: summary +  12153 in 00:00:30 =  405.3/s Avg:   250 Min:    34 Max: 13470 Err:    26 (0.21%) Active: 100 Started: 100 Finished: 0
2017-11-21 15:52:00,004 INFO o.a.j.r.Summariser: summary =  64749 in 00:02:46 =  390.6/s Avg:   254 Min:    22 Max: 84469 Err:   150 (0.23%)
2017-11-21 15:52:30,069 INFO o.a.j.r.Summariser: summary +  12318 in 00:00:30 =  409.7/s Avg:   234 Min:    40 Max: 14107 Err:    17 (0.14%) Active: 100 Started: 100 Finished: 0
2017-11-21 15:52:30,070 INFO o.a.j.r.Summariser: summary =  77067 in 00:03:16 =  393.5/s Avg:   250 Min:    22 Max: 84469 Err:   167 (0.22%)
2017-11-21 15:53:00,004 INFO o.a.j.r.Summariser: summary +  11864 in 00:00:30 =  396.3/s Avg:   253 Min:    39 Max: 25669 Err:    33 (0.28%) Active: 100 Started: 100 Finished: 0

summary +是這三分鍾的數據,summary =是累計到當前時刻所有的數據

以黃色區域數據為例,4857是發出的請求數目,00:00:16是發出的時間, 308.1是每秒發出的請求,即吞吐量,Avg, Min, Max分別是平均響應時間,最小響應時間和最大響應時間,響應時間指的是從請求發出到收到響應的時間,Err后面跟的數據分別是錯誤數和錯誤比例。

對於summariser報告,可以通過寫一個簡單的腳本來解析並作圖形化展示,下面是用python寫的一個簡單腳本,可以畫平均時延和吞吐量,使用方法是

python summary.py test.log,下面是summary.py內容:

import matplotlib.pyplot as plt
import re
import sys

avgtime_data=[]
mintime_data=[]
maxtime_data=[]
throughput_data=[]

logfile=open(sys.argv[1])
try:
    while True:
        line=logfile.readline()
        if line=='':
            break
        if line.startswith('summary ='):
            result=re.split(r'\s+', line)
            avgtime_data.append(result[8])
            throughput=result[6]
            throughputvalue=throughput[:-2]
            throughput_data.append(throughputvalue)
finally:
    logfile.close()

plt.figure(figsize=(8,4))
plt.ylim(0,60)
plt.plot(avgtime_data,color="red",label="Avg ResponseTime (milliseconds)")
plt.plot(throughput_data,color="green",label="ThroughPut (/s)")
frame = plt.gca()
frame.axes.xaxis.set_ticklabels([])
plt.xlabel("Duration, 2013/06/25 16:30:00 -- 2013/06/28 6:00:00, about 60 hours")
plt.title("sundong Jmeter Test Report")
plt.legend()
plt.show()

注意里面用到了正則表達式,其實在log文件非常大的時候,每行都進行正則匹配,效率是很低的。分享下我們項目使用的切片方法寫的rpc-server,效率要高出10幾倍

import sys

reload(sys)
sys.setdefaultencoding('utf8')
import zerorpc


class RPCServer(object):
    def getLogData(self,filename):
        avgtime_data=[]
        throughput_data=[]
        tps_data=[]
        tpsput_data=[]
        with open(filename, 'r') as f:
            for line in f:
                if 'summary =' in line:
                    rs = line.split('Avg:')
 avgtime_data.append(rs[1][0:6])
 throughput_data.append(rs[0][-10:-3]) return avgtime_data,throughput_data

s = zerorpc.Server(RPCServer())
s.bind("tcp://0.0.0.0:4242")
s.run()

通過rpc server獲取jmeter master的log日志里的數據,應用通過rpc client進行調用

 

參考:

1、http://blog.csdn.net/just_lion/article/details/9209253


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM