1

我想在负载下获取一些 PHP 应用程序的指标。为此,我在我的 web 应用程序上生成了很多请求。在 web 应用程序中,我正在收集指标(执行时间、API 请求延迟等),这些指标通过 FirePHP 标头返回给响应。在 JMeter 计划中,我想收集这些信息并直接处理它们以生成图表,或者将它们存储在日志文件中。

响应标头如下所示:

...
X-Wf-1-1-1-31: 610|[{"Type":"LOG","File":"somescript.php","Line":7},{"duration":"1.7108917236328 ms","notes":{"invokation":["Solr_Connector::exec","somescript2.php line : 42"],"size_download":"2167 bytes","query":"...url data ..."},"name":"[tag1][tag2]SOLR REQUEST 1382626844.906"}]|
X-Wf-1-1-1-32: 611|[{"Type":"LOG","File":"somescript.php","Line":7},{"duration":"1.7011165618896 ms","notes":{"invokation":["Solr_Connector::exec","somescript2.php line : 42"],"size_download":"2590 bytes","query":"...url data ..."},"name":"[tag1][tag3]SOLR REQUEST 1382626844.9079"}]|
X-Wf-1-1-1-33: 611|[{"Type":"LOG","File":"somescript.php","Line":7},{"duration":"1.5978813171387 ms","notes":{"invokation":["Solr_Connector::exec","somescript2.php line : 42"],"size_download":"2452 bytes","query":"...url data ..."},"name":"[tag1][tag3]SOLR REQUEST 1382626844.9097"}]|
X-Wf-1-1-1-34: 610|[{"Type":"LOG","File":"somescript.php","Line":7},{"duration":"1.662015914917 ms","notes":{"invokation":["Solr_Connector::exec","somescript2.php line : 42"],"size_download":"3150 bytes","query":"...url data ..."},"name":"[tag1][tag2]SOLR REQUEST 1382626844.9115"}]|
...

如何设置 JMeter 正则表达式提取器以提取名称以 "X-Wf-" 开头的标头的所有值?

4

1 回答 1

1

我了解响应标头将是:

响应标头:

HTTP/1.1 200 正常

服务器:Apache-Coyote/1.1

X-Wf-1-1-1-31: 610|[{"Type":"LOG","File":"somescript.php","Line":7},{"duration":"1.7108917236328 ms" ,"notes":{"invokation":["Solr_Connector::exec","somescript2.php line : 42"],"size_download":"2167 bytes","query":"...url 数据 ... "},"name":"[tag1][tag2]SOLR 请求 1382626844.906"}]|

X-Wf-1-1-1-32: 611|[{"Type":"LOG","File":"somescript.php","Line":7},{"duration":"1.7011165618896 ms" ,"notes":{"invokation":["Solr_Connector::exec","somescript2.php line : 42"],"size_download":"2590 bytes","query":"...url 数据 ... "},"name":"[tag1][tag3]SOLR 请求 1382626844.9079"}]

...

以这种方式组织测试计划: 测试计划概述

  • Regextractor 会将标题提取到名为 headers_1、headers_2 的变量中...

正则提取器配置

  • 对于每个控制器,将迭代 headers_i 并公开标头变量

ForEach 控制器配置

  • 使用 Groovy 的 JSR223 采样器会将标头(由 For EachController 公开)写入文件

JSR223 采样器

代码:

导入 org.apache.commons.io.FileUtils;

FileUtils.write(new File("/results.csv"), vars["header"]+"\r\n","UTF-8", true);

PS:不确定修改响应以放置此类信息是否是一个好主意,因为它会干扰初始应用程序的性能。

于 2013-10-25T08:12:00.173 回答