JMeter - how to log the full request for a failed response?

后端 未结 4 556
无人共我
无人共我 2020-12-08 13:21

i\'m using JMeter command line to stress test our website api. Now, here\'s a sample result i\'m getting back:

Creating summariser 
Created th         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 13:58

    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.

提交回复
热议问题