57

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!

skaffman
  • 398,947
  • 96
  • 818
  • 769
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

5 Answers5

83

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:

View Results Tree 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:

Save Responses to a file

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
rodrigoap
  • 7,405
  • 35
  • 46
  • 5
    Correct, but i was doing this via the command line .. so I don't have access to the GUI. Bu tI didn't specify that in my question (blush). Also, i couldn't figure out how to do it via the command line, so I ended up doing what you suggested anyways :) – Pure.Krome Oct 07 '09 at 03:37
  • 2
    If you are using the command line you can configure your test to send the data to an output file (jtl) and then process that file with this tool: http://jmeter-plugins.org/wiki/JMeterPluginsCMD/ to export to PNG or CSV. – Hernan Veiras Oct 27 '15 at 18:53
  • If I read the question correctly, was looking for the logged request not response...? – arcseldon Sep 22 '17 at 14:18
  • @arcseldon good catch! The full request and response are recoreded. – rodrigoap Sep 23 '17 at 23:39
  • @rodrigoap - have slightly adjusted your answer, `both the request and response`.. – arcseldon Sep 24 '17 at 03:40
26

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.

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
haridsv
  • 9,065
  • 4
  • 62
  • 65
  • I added the ability to control the log using a UDV called "DEBUG", so it is easier to leave the assertion for the regular workloads, and enable it only when necessary. – haridsv Dec 19 '12 at 07:13
  • @haridsv Nice Decision! But is it possible to save the requestData which caused failed response? – ShurupuS Jun 26 '13 at 13:15
  • @ShurupuS Per the component reference on `BeanShell Assertion`, `RequestHeaders` is available as a variable to the BeanShell code, so it is possible in theory. – haridsv Jun 27 '13 at 13:37
  • @haridsv can you help me with this? – ShurupuS Jun 27 '13 at 17:58
  • In above solution what is "DEBUG" variable. Where and why we need to define "DEBUG" variable – Saagar Oct 25 '18 at 14:02
6

There is a 'Save responses to a file' listener, which can save to file only when error occurs.

gWay
  • 1,087
  • 9
  • 7
4

This is how I log the full request (request URL + request body) for failed requests.

  1. 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.

sogwiz
  • 486
  • 3
  • 14
  • what kind of listener is this that you added this code to? – Kir Aug 19 '20 at 04:27
  • I used a JSR223 listener. More info about it here: https://www.pushbeta.com/2019/10/18/jmeter-logging-the-full-request-for-non-gui-access/ – sogwiz Sep 05 '20 at 15:42
0

2023-04-22

I added a BeanShell PostProcessor to very top level and have this code:

if (!ctx.getPreviousResult().isSuccessful()){
    String httpResponseBody = new String(ctx.getPreviousResult().getResponseData());
    log.error(httpResponseBody);
}
Surasin Tancharoen
  • 5,520
  • 4
  • 32
  • 40