一、在jemter中,在后置处理器bean shell中可以通过引入org.apache.jmeter.samplers.SampleResult;
从而对取样器结果分析处理,现在说明一下最常用的几个函数:
import org.apache.jmeter.samplers.SampleResult;
String samplerData= prev.getSamplerData();
log.info("getSamplerData=======:"+samplerData); //响应结果
String threadName = prev.getThreadName();
log.info("ThreadName:"+threadName ); //得到threadname
String getCookies = prev.getCookies();
log.info("getCookies:"+ getCookies);
String getDataEncodingWithDefault = prev.getDataEncodingWithDefault();
log.info("getDataEncodingWithDefault:"+ getDataEncodingWithDefault);
String getHTTPMethod = prev.getHTTPMethod();
log.info("getHTTPMethod:"+ getHTTPMethod);
int getBodySize = prev.getBodySize(); //获取返回报问题的大小
log.info("getBodySize:"+ getBodySize);
int getTime = prev.getTime();//获取该笔请求的耗时
log.info("getTime:"+ getTime);
脚本执行结果如下:
2020-07-01 16:15:31,936 INFO o.a.j.u.BeanShellTestElement: ThreadName:认购书发起合同 1-1 2020-07-01 16:15:31,936 INFO o.a.j.u.BeanShellTestElement: getCookies: 2020-07-01 16:15:31,936 INFO o.a.j.u.BeanShellTestElement: getDataEncodingWithDefault:UTF-8 2020-07-01 16:15:31,936 INFO o.a.j.u.BeanShellTestElement: getHTTPMethod:POST 2020-07-01 16:15:31,936 INFO o.a.j.u.BeanShellTestElement: getRedirectLocation:null 2020-07-01 16:15:31,936 INFO o.a.j.u.BeanShellTestElement: getBodySize:248966 2020-07-01 16:15:31,936 INFO o.a.j.u.BeanShellTestElement: getTime:2994
结果树的结果如图

尤其是 getBodySize()和getTime()两个函数,在做大并发场景下,输出超时的请求,方便对这笔业务做进一步分析,分析定位响应超时的问题;
if(getTime> 2000){
log.info("该笔请求的traceid 是"+ "${traceId}");
log.info("Respnse is " + response);
log.info(code);
}
这样就可以输出流水号,方便进行问题定位分析。
另外http://svn.apache.org/repos/asf/jmeter/branches/docs-2.9/docs/api/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.html可以查看所有的SampleResult包含的方法。
大致如下:

