JMeter - how to log the full request for a failed response?
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!
Solution 1:
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:
Solution 2:
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:
if (Boolean.valueOf(vars.get("DEBUG"))) {
for (a: SampleResult.getAssertionResults()) {
if (a.isError() || a.isFailure()) {
log.error(Thread.currentThread().getName()+": "+SampleLabel+": Assertion failed for response: " + new String((byte[]) ResponseData));
}
}
}
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.
Solution 3:
There is a 'Save responses to a file' listener, which can save to file only when error occurs.
Solution 4:
This is how I log the full request (request URL + request body) for failed requests.
- Add a Listener inside the Thread Group
try{ var message = ""; var currentUrl = sampler.getUrl(); message += ". URL = " +currentUrl; var requestBody = sampler.getArguments().getArgument(0).getValue(); message += " --data " + sampler.getArguments(); if(!sampleResult.isSuccessful()){ log.error(message); } }catch(err){ //do nothing. this could be a debug sampler. no need to log the error }
For every Sampler inside the Thread Group, the Listener will execute this code after the Sampler.