Lena
Lena

Reputation: 51

Setting sample_variables property at runtime

Is there a way to specify a list of variables to be saved in the output file at runtime and not in jmeter.properties file?

I am currently specifying the list of variables to be saved in sample_variables, in jmeter.properties file, but this does not allow specifying different set of output variables for each JMeter script, unless I keep updating jmeter.properties file.

Upvotes: 2

Views: 1583

Answers (2)

Dmitri T
Dmitri T

Reputation: 168197

You can pass sample_variables (as well as any other property) via -J command line argument like:

jmeter -Jsample_variables=foo -n -t script1.jmx
jmeter -Jsample_variables=bar,baz -n -t script2.jmx

Also, as per Managing Properties chapter of JMeter User manual:

When you need to modify jmeter properties, ensure you don't modify jmeter.properties file, instead copy the property from jmeter.properties and modify its value in user.properties file.

See Apache JMeter Properties Customization Guide article for comprehensive information on different JMeter properties types and ways of working with them

Upvotes: 2

timbre timbre
timbre timbre

Reputation: 13995

I am not aware of the way to change sample_variables at runtime. The only workaround I know of is to have BeanShell Listener (or alternatively one of the programmable sampler/pre-/post-processors), which writes into its own file. E.g.:

String filename = "myfile.txt";

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

FileOutputStream f = new FileOutputStream(filename, true);
PrintStream p = new PrintStream(f); 
this.interpreter.setOut(p); 
print(message);
f.close(); 

You can also add conditions when the variable should be saved (e.g. only after specific sampler or only when the value have changed). From my experience the solution with BeanShell Listener is not expensive resources-wise, since it will be 1 thread regardless of number of running threads. Solution with programmable pre-/post-processor is usually more expensive, unless you only save variables rarely.

Upvotes: 0

Related Questions