Jmeter doesn't interpreter machineName() variable - jmeter

I faced with a strange issue. I need a jmeter to generate jtl and log files where name of the file will be hostname where jmeter is running on. For this task I found internal variable "__machineName()" in my case it works but only partially. Below is example:
jmeter ... -l ${__machineName()}.jtl -j ${__machineName()}.log
But result is a bit strange:
${__machineName()}.log 328-15-09-2020-15-02-42-95r4v.jtl
It works but only for jtl file! I've tried other variables and had the same result.
Have you faced with such issues?
Additional info: execution of jmeter is wrapped in the script that receives all properties as string and just execute it, therefore ideas about usage of shell commands won't work. Result will look the following way:
`hostname`.log or ${HOSTANME}.log
Workflow:
Python generate string with paramaters for jmeter execution. I'm using Jinja here. Part of the code:
Template( -Djava.net.preferIPv4Stack=true \
-l {{ log_dir }}/${__machineName()}.jtl \
-j {{ log_dir }}/${__machineName()}.log)
Python schedule Kubernetes Job and pass string with properties to the jmeter
Container with jmeter has entrypoint script here it set some Java params and start jmeter. Part where jmeter receives string with properties:
...
export JVM_ARGS="-Xmn${n}m -Xms${s}m -Xmx${x}m"
jmeter $#
Jmeter execute test with specific params and write logs. Exactly here I faced with a problem that ${__machineName()} works ok for -l(jtl log) param and doesn't work for -j(log) param.

The function will not be executed as it's between your shell and log4j logging system, you need to fix your shell script in order to be able to shell commands.
If for some reason you cannot amend your shell script it should be possible to change JMeter logging configuration so it would contain environment variable lookup
Necessary changes to log4j2.xml file (lives in "bin" folder of your JMeter installation)
Add this block to define HOSTNAME property reading the underlying OS environment variable
<Properties>
<Property name="HOSTNAME">${env:HOSTNAME}</Property>
</Properties>
Change this line:
<File name="jmeter-log" fileName="${sys:jmeter.logfile:-jmeter.log}" append="false">
to this one:
<File name="jmeter-log" fileName="${HOSTNAME}.log" append="false">
so next time you start your test JMeter will create the log file with using your machine hostname as the filename and you won't have to pass it via command-line argument.
More information: How to Configure JMeter Logging

Related

Jmeter displays doubled results when running in non gui mode

I have a Test plan which when I run in the Gui Mode execute the sampler one time, but when I start the Test Plan from the command line I get the sampler to be running twice.
I have deleted the result.jtl file to insure that the results are not accumulated.
Without seeing your test plan it's hard or even impossible to say what's the reason as there are too many possible options, the most straightforward I can think of is:
You have a Listener (or two) somewhere in the test plan configured to write data into the same file which you specify via -l command-line argument
You have resultcollector.action_if_file_exists=APPEND property defined somewhere
So try out the following way of running the test:
jmeter -n -t test.jmx -l result.jtl -f -Jresultcollector.action_if_file_exists=DELETE
where:
-f forces JMeter to overwrite the .jtl results file
resultcollector.action_if_file_exists=DELETE property does the same for Listeners
More information:
Full list of JMeter command-line options
JMeter Properties Reference
Apache JMeter Properties Customization Guide

JMeter prints summary view on the command line for one script but not another

I have 2 JMeter scripts which I am running from the command line. In the first script, I can see the summary view on the console while the test is running. That is:
summary + 3234 in 00:00:30...
summary = 34872 in 00:31:30...
In the other script, none of the summary data is printed, although the script will run correctly and save the data to the output file.
I see the same behavior for these script whether I run them from a Windows command line or from Linux. What is the trick to enable the summary output for my second script?
I can think of 2 options:
Your "other" script runs less than 30 seconds and by default Summariser "ticks" every 30 seconds. If this is the case you can amend summariser.interval property so it would occur more frequently
You have Transaction Controllers everywhere in your "other" script and by default Summariser doesn't report the sample results originating from the Transaction Controllers. If this is the case - set summariser.ignore_transaction_controller_sample_result property to false
More information:
Configuring JMeter
Summariser - Generate Summary Results - configuration
Seeing similar behavior. The result summary is not printed when I use conf path parameter to run the script. Whereas it is shown when I remove the -p parameter
jmeter -n -t fullpathtojmx -p fullpathtopropertiesfile -l fullpathtojtlfile

How to run jmeter jmx files parallely from single command prompt

I have 5 different jmx files in my project. I need to do performance testing by running all these jmx files parallely. Currently i'm opening 5 different jmeter command prompt instance and triggering the execution.
Is there any way i can execute all these jmx files from 1 jmeter command prompt?
Depending on your operating system the options are in:
Linux: there is a parallel command, you can go for something like:
parallel --gnu << 'EOF'
jmeter -n -t test1.jmx -l result1.jtl
jmeter -n -t test1.jmx -l result2.jtl
etc.
EOF
Windows: you can create a batch script assuming start command something like:
start jmeter -n -t test1.jmx -l result1.jtl
start jmeter -n -t test2.jmx -l result2.jtl
etc.
As a cross-platform unified solution you can consider using Taurus tool as a wrapper for your JMeter script you can kick off multiple JMeter tests in parallel using simple declarative YAML syntax like:
---
execution:
- scenario:
script: test1.jmx
- scenario:
script: test2.jmx
- scenario:
script: test3.jmx
#etc
See Taurus - Working with Multiple JMeter Tests for more details.
You need to use some other tools like Ant or Maven or jenkins for that.
Please check the below link for more information:-
How to run multiple jmx scripts together in JMeter
Praveen, I don't think this is currently possible in JMeter to execute multiple .jmx files from single command , but I would suggest adding all 5 scripts in a single .jmx file if possible in your scenario.

Throughput Shaping timer- Externalising

I want to externalise the value for throughput shaping timer But not from Jmeter or User.properties as I have couple of other script to be executed with different work load model. I want a separate property file specifying the load pattern can you kindly suggest.
There is a load_profile property, you can define the desired Throughput Shaping Timer load model via it.
If you don't want to write down the value into jmeter.properties or user.properties file to permanently change the profile you can pass it via -J command line argument instead like:
jmeter -Jload_profile=const(10,10s) line(10,100,1m) step(5,25,5,1h) -n -t ...
Having separate file is also not a problem,
Create, i.e. test1.properties file in the "bin" folder of your JMeter installation
Put your desired load profile there:
load_profile=const(10,10s) line(10,100,1m) step(5,25,5,1h)
Pass this file to JMeter via -q command-line argument like:
jmeter -q test1.properties -n -t ...
Repeat steps 1-3 for 2nd test, you will be able to run it like:
jmeter -q test2.properties -n -t ...
References:
Full list of JMeter's command-line options
Configuring JMeter
Apache JMeter Properties Customization Guide

How to email the updated test result in jmeter

I have a simple HTTP Request sampler in a test plan. And, viewing the result through "Aggregate Report" and writing the same results to a file. I have used "SMTP Sampler" in "tearDown Thread Group" and also used the "Test Action" to wait for a while.
Issue is, once I execute the test-case, in mail I got the previous run results instead of the new one.
Here is the screen-shot of my test plan.
Please help. Thanks in advance!
I don't like your "Test Action to wait for a while" approach as it may be not enough so you won't be able to tell for sure whether JMeter stored the most recent results or not.
I would suggest the following: add jmeter.save.saveservice.autoflush=true line to user.properties file (it's located under /bin folder of your JMeter installation) and on next JMeter start it will be storing every single line.
So
Apply aforementioned property change
Configure your SMTP Sampler to send results.jtl file
Disable all the listeners.
Run JMeter in command-line non-GUI mode as follows
jmeter -n -t /path/to/your/testplan.jmx -l /path/to/results.jtl
As an alternative to editing user.properties file you can pass the property via -J command line argument like:
jmeter -Jjmeter.save.saveservice.autoflush=true -n -t /path/to/your/testplan.jmx -l /path/to/results.jtl
See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of working with them.

Resources