JMeter - 如何记录失败响应的完整请求?
我正在使用 JMeter 命令行对我们的网站 api 进行压力测试。现在,这是我返回的示例结果:
Creating summariser <summary>
Created the tree successfully using street_advisor.jmx
Starting the test @ Sat Oct 03 15:22:59 PDT 2009 (1254608579848)
Waiting for possible shutdown message on port 4445
summary + 1 in 0.0s = 37.0/s Avg: 27 Min: 27 Max: 27 Err: 1 (100.00%)
<snip a few more lines>
<then i break it>
所以我收到错误。
目前,所有错误都将保存到文件中。当我检查该文件时,它说它是 404。呃..好吧。无论如何,我可以确切看到请求 JMeter 尝试了什么吗?
这是我的配置文件的片段...
<ResultCollector guiclass="SimpleDataWriter" testclass="ResultCollector" testname="Error Writer" enabled="true">
<boolProp name="ResultCollector.error_logging">true</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>false</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>false</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>true</xml>
<fieldNames>false</fieldNames>
<responseHeaders>true</responseHeaders>
<requestHeaders>true</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename">./error.jtl</stringProp>
</ResultCollector>
现在,在有人说“检查网络服务器日志文件”之前,我知道我可以做到这一点,是的,我找到了 404 ..但我希望看看是否可能无需访问它们..特别是如果它们位于另一台服务器上和/或我无法访问它们。 请帮忙!
i'm using JMeter command line to stress test our website api. Now, here's a sample result i'm getting back:
Creating summariser <summary>
Created the tree successfully using street_advisor.jmx
Starting the test @ Sat Oct 03 15:22:59 PDT 2009 (1254608579848)
Waiting for possible shutdown message on port 4445
summary + 1 in 0.0s = 37.0/s Avg: 27 Min: 27 Max: 27 Err: 1 (100.00%)
<snip a few more lines>
<then i break it>
So i'm getting an error.
Currently, all errors are going to a file. When i check that file, it's saying it's a 404. Er.. ok. Is there anyway i can see exactly what the request JMeter tried?
here's a snippet of my config file...
<ResultCollector guiclass="SimpleDataWriter" testclass="ResultCollector" testname="Error Writer" enabled="true">
<boolProp name="ResultCollector.error_logging">true</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>false</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>false</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>true</xml>
<fieldNames>false</fieldNames>
<responseHeaders>true</responseHeaders>
<requestHeaders>true</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename">./error.jtl</stringProp>
</ResultCollector>
Now, before someone says 'Check the webserver log files', I know I can do this and yep, I've found the 404 .. but i'm hoping to see if it's possible without accessing them .. especially if they are on another server and/or I can't get access to them.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看结果树组件显示所有结果的树示例响应,允许您查看任何示例的请求和响应。
负载测试时(始终处于非 GUI 模式),填写“文件名”字段并选择仅保存错误响应:
正如您在上面看到的,我们单击了“配置”选择除 CSV 字段之外的所有字段。
您还可以使用将响应保存到文件将整个响应保存到文件中:
The View Results Tree component shows a tree of all sample responses, allowing you to view both the request and response for any sample.
When load testing (Always in NON GUI mode), fill in "Filename" field and select to only save Responses in Error:
As you can see above we clicked on Configure to select all fields except CSV ones.
You can also save the entire response to a file using Save Responses to a file:
我发现此线程正在寻找一种解决方案,仅在采样器失败时记录响应,因此接受的解决方案对我来说并不好。我在涉及数十万个样本的非常高的负载下偶尔会出现样本失败,因此树侦听器对我来说完全不切实际(它将达到几千兆字节的大小),所以这就是我想出的(这应该对我有用) OP 的场景也是如此):
添加一个
[JSR223 Assertion][1]
(应该在所有其他断言之后)并将以下代码放入其中:这将导致整个响应被记录到jmeter 日志文件在我的情况下很好,因为我知道响应非常小,但对于大响应,可以进行更智能的处理。
I found this thread searching for a solution to log the response only when a sampler fails, so the accepted solution is not good for me. I have occasional sample failures at a very high load involving hundreds of thousands of samples, so a tree listener is completely impractical for me (it will reach several gigabytes in size), so here is what I came up with (which should be good for the OP's scenario as well):
Add a
[JSR223 Assertion][1]
(should come after all the other assertions) and put the below code in it:This will cause the entire response getting logged to the jmeter log file which is fine in my case, as I know that the responses are really small, but for large responses, more intelligent processing could be done.
有一个“将响应保存到文件”侦听器,仅当发生错误时才可以将响应保存到文件。
There is a 'Save responses to a file' listener, which can save to file only when error occurs.
这就是我记录失败请求的完整请求(请求 URL + 请求正文)的方式。
对于线程组内的每个 Sampler,Listener 将在 Sampler 之后执行此代码。
This is how I log the full request (request URL + request body) for failed requests.
For every Sampler inside the Thread Group, the Listener will execute this code after the Sampler.
2023-04-22
我将 BeanShell PostProcessor 添加到最顶层并具有以下代码:
2023-04-22
I added a BeanShell PostProcessor to very top level and have this code: