JMeter - 如何记录失败响应的完整请求?

发布于 2024-08-06 19:59:05 字数 2459 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

酒几许 2024-08-13 19:59:05

查看结果树组件显示所有结果的树示例响应,允许您查看任何示例的请求和响应。

负载测试时(始终处于非 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:

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

坦然微笑 2024-08-13 19:59:05

我发现此线程正在寻找一种解决方案,在采样器失败时记录响应,因此接受的解决方案对我来说并不好。我在涉及数十万个样本的非常高的负载下偶尔会出现样本失败,因此树侦听器对我来说完全不切实际(它将达到几千兆字节的大小),所以这就是我想出的(这应该对我有用) OP 的场景也是如此):

添加一个 [JSR223 Assertion][1] (应该在所有其他断言之后)并将以下代码放入其中:

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));
    }
  }
}

这将导致整个响应被记录到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:

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.

⊕婉儿 2024-08-13 19:59:05

有一个“将响应保存到文件”侦听器,仅当发生错误时才可以将响应保存到文件。

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

平安喜乐 2024-08-13 19:59:05

这就是我记录失败请求的完整请求(请求 URL + 请求正文)的方式。

  1. 在线程组中添加监听器

<前><代码>尝试{
var 消息 = "";
var currentUrl = Sampler.getUrl();
消息+=“.URL=”+currentUrl;
var requestBody = Sampler.getArguments().getArgument(0).getValue();
消息+=“--data”+sampler.getArguments();

if(!sampleResult.isSuccessful()){
日志.错误(消息);
}

}捕获(错误){
//什么都不做。这可能是一个调试采样器。无需记录错误
}

对于线程组内的每个 Sampler,Listener 将在 Sampler 之后执行此代码。

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.

奶气 2024-08-13 19:59:05

2023-04-22

我将 BeanShell PostProcessor 添加到最顶层并具有以下代码:

if (!ctx.getPreviousResult().isSuccessful()){
    String httpResponseBody = new String(ctx.getPreviousResult().getResponseData());
    log.error(httpResponseBody);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文