标签:类型 sim 生成 through .text exce shel man 请求
压测目标:error 为0,线程起到250,服务器配置达到最大
一.Jmeter3.1 压测
JMeter3.1提供一个用于生成HTML页面格式图形化报告的扩展模块。该模块支持通过两种方式生成多维度图形化测试报告:
其默认提供的度量维度包括:
- Latency time = 接收到响应的第一个字节的时间点 - 请求开始发送的时间点
from just before sending the request to just after the first response has been received
-- Apache JMeter Glossary
- 响应时间(JMeter术语中的Elapsed time) = 接收完所有响应内容的时间点 - 请求开始发送的时间点
from just before sending the request to just after the last response has
been received
-- Apache JMeter Glossary
二.配置参数修改
1.确认基本配置
jmeter.save.saveservice.data_type=true
jmeter.save.saveservice.label=true
jmeter.save.saveservice.response_code=true
# response_data is not currently supported for CSV output
jmeter.save.saveservice.response_data=true
# Save ResponseData for failed samples
jmeter.save.saveservice.response_data.on_error=false
jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.subresults=true
jmeter.save.saveservice.assertions=true
jmeter.save.saveservice.latency=true
jmeter.save.saveservice.connect_time=true
jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.responseHeaders=true
jmeter.save.saveservice.requestHeaders=true
jmeter.save.saveservice.encoding=false
jmeter.save.saveservice.bytes=true
jmeter.save.saveservice.url=true
jmeter.save.saveservice.filename=true
jmeter.save.saveservice.hostname=true
jmeter.save.saveservice.thread_counts=true
jmeter.save.saveservice.sample_count=true
jmeter.save.saveservice.idle_time=true
# Timestamp format - this only affects CSV output files
# legitimate values: none, ms, or a format suitable for SimpleDateFormat
jmeter.save.saveservice.timestamp_format=ms
jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS
2.生成报告
a. 在压力测试结束时报告
b. 使用已有的压力测试CSV日志文件生成报告
两个样例都会在\apache-jmeter-3.0\bin\report目录下产生如下文件(夹):
用浏览器打开index.html文件,即可查看各种图形化报告:
注:在3.1版本,由于源码中字符编码的问题,可能会遇到生成的报告中,中文标签展示为乱码的问题
解决方案:修改JMeter report模块读取数据源码中的字符集设置为UTF-8,编译后替换到JMETER_HOME\lib\ext\ApacheJMeter_core.jar
附上:
1.监听接口脚本
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="3.1" jmeter="3.1 r1770033">
<hashTree>
<BeanShellListener guiclass="TestBeanGUI" testclass="BeanShellListener" testname="BeanShell Listener" enabled="true">
<stringProp name="filename"></stringProp>
<stringProp name="parameters"></stringProp>
<boolProp name="resetInterpreter">false</boolProp>
<stringProp name="script">import java.util.regex.*;
import txtWrite.*;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import org.apache.commons.io.FileUtils;
import org.apache.jmeter.assertions.AssertionResult;
import java.text.*;
import java.util.Date;
import org.apache.jmeter.functions.SamplerName;
import org.apache.jmeter.functions.AbstractFunction;
import java.lang.*;
StringBuffer aaa = new StringBuffer();
String bbb;
String ccc;
String eee;
String fff;
String sss = new SimpleDateFormat("yyyyMMdd-HH").format(new Date());
String result;
String ttt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
bbb = prev.getResponseDataAsString();
ccc = prev.getResponseHeaders();
eee = prev.getThreadName();
fff = prev.getSampleLabel();
AssertionResult[] ddd = prev.getAssertionResults();
for (int n=0;n < ddd.length;n++)
{
aaa.append("断言结果:"
+ ddd[n].isFailure().toString() + "|" +
"断言详情:" + ddd[n].getFailureMessage() +
"\r\n");
}
result =fff
+"\r\n\r\n" + "本地时间:" + ttt +
"\r\n\r\n" + eee +"\r\n\r\n" +
"响应结果:\r\n" + bbb + "\r\n\r\n"+
"header:\r\n" + ccc + "\r\n" + aaa +
"\r\n" +
"============================================================================================"
+ "\r\n";
if (aaa.toString().contains("true"))
{
File file = new File("C:\\我的文档\\jmeter脚本\\获取断言结果\\"+sss+".txt");
FileUtils.write(file,result,"utf-8",true);
}</stringProp>
</BeanShellListener>
<hashTree/>
</hashTree>
</jmeterTestPlan>
操作步骤及注意:
1.将脚本放到d盘
命令行切换到jme/bin目录下,执行命令
jmeter -n -t d:\9000-jmeter.jmx -l LogFile -e -o ./10report
2.
每执行一次,删除目录下的:LogFile,10report
命令行显示结果每30s刷新一次
3.查看bin目录下的10report目录下index.html文件,查看执行结果
chart-overtime-active threads over time,启动线程数
apdex:健康
Statistics:结果数据
4.BeanshellListener显示执行结果
5.分布式部署
代理机:
1.jdk,jmeter环境
2.输入“ipconfig”,找到IP地址,例如是:192.168.8.149
3.配置jmeter.properties
打开Jmeter/bin/jmeter.properties,找到”remote_hosts=127.0.0.1”,把这一行修改为”remote_hosts=192.168.8.149:1099,1099是端口号
4.启动jmeter-server.bat,
主机:
1.配置jmeter.properties
Jmeter/bin/jmeter.properties,找到”remote_hosts=127.0.0.1”,把这一行修改为”remote_hosts=192.168.8.149:1099,192.168.8.174:1099,1099是端口号,可以随意自定义。如果有多台代理机,这里需要把所有的代理机的IP地址和端口号都加入进来。
2.打开jmeter-server.bat文件,设置完成了
3.启动jemter.bat文件
4.运行-远程启动
标签:类型 sim 生成 through .text exce shel man 请求
原文地址:https://www.cnblogs.com/lisa2016/p/10645066.html