JMeter: Writing Sampler Data into the File

Method requires 2 post-processors on Sampler element:

Post-Processor 1
Type: Regular Expression Extractor
Extracts some data from the request into a variable (say, “myData”)

Post-Processor 2:
Type: BSF Post-Processor
Saves the extracted data in the variable into the file:

String filename = vars.get("userVariableWithFileName"); 
String message = "At " + System.currentTimeMillis() +" data is " + vars.get("myData");

FileOutputStream f = new FileOutputStream(filename, true);
PrintStream p = new PrintStream(f); 

vars.put("myData", "N/A"); // Make sure we don't accidentally record the same data twice

I would not recommend this method for large production-scale load tests, but for smaller tests it could be a quick and convenient way to retrieve and save some data from request, without changing script in any significant way. The performance of this piece largely depends on the the performance of the underlying hard disk, which is why it’s not good for large-scale performance. But it gives a lot of flexibility in how and what you write (e.g. each user could have its own file; the format of the file is absolutely up to you; you may do some statistics on the fly, and so on). Thus might be worth it.

JMeter: Writing Sampler Data into the File

2 thoughts on “JMeter: Writing Sampler Data into the File

  1. It is possible to “tell” JMeter to store certain variables values in .jtl results file along with the other key performance indicators. It is controllable via “sample_variables” property.

    So if you add the following line:


    into “” file (it sits in /bin folder of your JMeter installation) and restart JMeter the property will get applied and “myData” variable value will be appended to .jtl CSV results as the last column.

    Check out Apache JMeter Properties Customization Guide to learn more about different JMeter properties and ways of setting/overriding them.

    1. Yea, if there’s one script and one JMeter machine, this workaround could work too. Although I prefer JMeter test plans to be independent, self-sufficient and self-documenting, where’s this workaround in my opinion introduces invisible and hard to debug/maintain dependency between the particular test plan and JMeter installation.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s