简体   繁体   中英

Extracting FirePHP headers with JMeter

I would like to take some metrics of a PHP application under load. To do that , I'm generating a lot of request on my webapp. In the webapp I'm collecting metrics (execution time, API request latency etc...), which are returned to the response via FirePHP headers. In the JMeter plan, I would like to collect those informations and either directly process them to produce a graph or alternatively store them in a log file .

The response headers looks like this :

...
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"}]|
...

How can I set up the JMeter regular expression extractor in order to extract all the values of the header whose names starts with "X-Wf-" ?

I understand Response headers will be:

Response headers:

HTTP/1.1 200 OK

Server: 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 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"}]

...

Organize the Test Plan this way: 测试计划概述

  • Regextractor will extract headers to variables called headers_1, headers_2...

RegExtractor配置

  • For Each Controller will iterator over headers_i and expose header variable

ForEach Controller配置

  • JSR223 Sampler using Groovy will write header (exposed by For EachController) to file

JSR223采样器

Code:

import org.apache.commons.io.FileUtils;

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

PS : Not sure it's a good idea to modify response to put this kind of info as it will disturb performances of initial application .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM