0
votes

I have a JMeter script that goes through a bunch of requests, each being different, GETs, POSTs and so on...

Each request returns a custom header from the server that has some numeric values in it. This header returns the actual processing time it took on the server side (without latency/http overhead)

I was able to add a Regular Expression Extractor to get that value from the header without any problems, however I would like this to be repeated for all the requests.

By using Debug Sampler I can see that the extractor only runs once, seems to be the last instance.

How can I have an extractor that runs all all requests and collects all the values from the header.

Bonus question. Finally I would love to be able to aggregate these values and get one average value.

Disclaimer: This other question is similar to mine but it doesn't explain how to actually do it in terms of the locations of the extractor and the debug sampler.

Track results of a regular expression extractor in JMeter

Thank you.

2

2 Answers

1
votes

Just put Regular Expression Extractor at the same level as your HTTP Request samplers and it will be applied to all of them

JMeter Regular Expression Extractor

See Scoping Rules User Manual entry for more detailed explanation.

With regards to value collection the best option is using Sample Variables property. Given you store your header value into a variable called ${foo} you can get it appended to jtl results file by adding the next line to the user.properties file:

sample_variables=foo

JMeter restart will be required to pick the property up. The other way (which doesn't require restart) is passing the property via -J command-line argument as

jmeter -Jsample_variables=foo -n -t test.jmx -l result.jtl

As the result you will get an extra column called foo in the .jtl results file and it will hold the ${foo} variable value for each Sampler. Upon test completion you will be able to open .jtl results file with MS Excel or equivalent and use AVERAGE function to get the value you're looking for.

See Apache JMeter Properties Customization Guide for more information on setting and amending various JMeter properties for Configuring JMeter according to your needs.

0
votes

While Dmitri's answer is one way of doing it. But I wanted something different than each time exporting it into a file and post processing it...

I ended up doing this "manually"

By manually I mean I added a BSF Assertion with language = JavaScript and then wrote some JavaScript to do this:

  1. Pull the value out of the header (if found)
  2. Keep a record of total/count using variables
  3. Updating a variable that shows the aggregate always
  4. Add Debug Sampler to get easy access to the values after the test.

The following is the code that I used in the BSF Assertion:

var responseHeaders = prev.getResponseHeaders();

var xNodetasticRt = /x-nodetastic-rt: (\d+\.?\d*)/.exec(responseHeaders);

if (xNodetasticRt) {
    var value = parseFloat(xNodetasticRt[1]);

    vars.put("xNodetasticRt", value); 

    var total = parseFloat(vars.get("xNodetasticRt-Total")); 
    if (!total) {
        total = 0.0;
    }
    total += value;
    vars.put("xNodetasticRt-Total", total);

    var count = parseFloat(vars.get("xNodetasticRt-Count")); 
    if (!count) {
        count = 0;
    }
    count++;
    vars.put("xNodetasticRt-Count", count);

    vars.put("xNodetasticRt-Average", total / count);
}