ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

linux环境下python汇总jmeter聚合报告生成HTML报告

2022-05-02 21:32:18  阅读:176  来源: 互联网

标签:python summary HTML file linux report path jmeter os


# -*- coding:UTF-8 -*-
import os
import io
import os.path
import shutil
def del_file(path):
if not os.listdir(path):
print('it is null')
else:
for i in os.listdir(path):
path_file = os.path.join(path,i)
if os.path.isfile(path_file):
os.remove(path_file)
else:
del_file(path_file)
shutil.rmtree(path_file)

def writefile_title(path,summary_all):
reportfile = path + '/' + summary_all
file=open(reportfile,'w')
file.write('timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect\n')

def findfile(path_report,summary):
i=0
file_dir=[]
for root, dirs, files in os.walk(path_report):
for file_name in files:
if summary in file_name:
result=os.path.join(root, file_name).replace('/', '/')
i += 1
file_dir.append(result)
return file_dir

def writefile_content(file_dir,summary_all):
l = len(file_dir)
reportfile = path + '/' + summary_all
f_2 = io.open(str(reportfile), "a+")
for i in range(0,l):
file=file_dir[i]
print(file)
f=io.open(str(file), "r",encoding='UTF-8',errors='ignore')
data=f.readlines()
f.close()
j=0
for line in data:
if (j >= 1):
line=line
f_2.write(line)
j += 1
f_2.close()
if __name__ == '__main__':
summary='聚合报告.jtl'
summary_all='report_all.jtl' #汇总的聚合报告名称
path_report=r'/opt/jmeter/apache-jmeter-3.1/TestReport'
path=r'/opt/jmeter/apache-jmeter-3.1/report_all' #汇总报告存放路径
del_file(path)
file_dir = findfile(path_report,summary) #查找各接口的聚合报告的存放路径
writefile_title(path,summary_all) #写汇总报告的首行标题
writefile_content(file_dir,summary_all) #写汇总报告的内容


python脚本如上所示,脚本会去读取指定路径下的所有测试计划的聚合报告,并将文件里的内容都写入report_all.jtl里,
python脚本文件名为:report_all.py
通过命令:chmod 755 $filepath/report_all.py; 给python文件赋权
通过命令:python $filepath/report_all.py; 执行python文件,前提条件:linux环境下安装有python
通过命令:cd /opt/jmeter/apache-jmeter-3.1//lib/ext; 进入jmeter的JMeterPluginsCMD.sh所在目录 (只有进入此目录才可执行聚合报告转换命令
执行命令:jmeter -g $filepath/report_all/report_all.jtl -o $filepath/report_all/聚合报告; 将jtl格式的聚合报告转换成html格式的。


 

 

 

标签:python,summary,HTML,file,linux,report,path,jmeter,os
来源: https://www.cnblogs.com/yan-test/p/16216906.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有