I'm using some JMeter's functions in my HTTP request using (version 3.1). In particular I'm using __time() function and it works fine if I execute the test plan in local machine, either using CLI or GUI, but when I connect to remote JMeter in server mode (same version) the function are not evaluated and my HTTP request contains the function verbatim.
I created a test plan named MyHTTPTest.jmx wich sends HTTP request and contains this function in body: ${__time(YMDHMS)}.
If I execute the test in local machine:
bin/jmeter.sh -n -t MyHTTPTest.jmx
my request contains 20161229-123355 and it works as expected.
If I execute the test plan using remote servers, for example:
remote-server: bin/jmeter.sh -s
local-server: bin/jmeter.sh -n -R remote-server -t MyHTTPTest.jmx
my request contains ${__time(YMDHMS)} verbatim and time function is not evalueted.
I tried other functions and I created user defined variable initialized with function value but the problem persist.
What I am doing wrong?
Related
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
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
The current setup is as follows: 4 Ubuntu boxes one master and 3 slaves. I've been encountering the following issues when executing the tests from command-line in distributed fashion.
If I execute the tests and try to generate the HTML report, JMeter attempts to create the files after each of the machines finish their runs, this causes conflicts as the first machine that finished had already created the HTML folder.
./jmeter -r -n -t ./Jmeter_Performance_PoC.jmx -l ./TestResults.csv -e -o TestResults
If I execute the tests and just generate the CSV report to then generate the HTML report from the CSV file, the report gets generated, but JMeter is not using the files full information, it is not identifying the different thread groups nor is it displaying the execution information per slave.
./jmeter -r -n -t ./Jmeter_Performance_PoC.jmx -l ./TestResults.csv
./jmeter -g ./TestResults.csv -o ./results
Is there a way of having JMeter generate the consolidated report in distributed execution without having override conflicts?
Just use __machineIP() or __machineName() as a prefix or postfix for the Thread Groups / Samplers labels - this way you (and JMeter) will be able to distinguish the results coming from the different slaves.
Check out Apache JMeter Functions - An Introduction to get familiarized with the JMeter Functions concept.
So, I'm trying to call a function on a remote machine using EOF in bash.
Here is an example:
#!/bin/bash
other_func() {
c='This is it';
echo $c;
}
test_func() {
a='this is some random string'
ssh -i "somepemkey.pem" ubuntu#xx.xx.xx.xx << EOF
b='some random sting inside remote server';
echo $a;
echo \$b;
other_func
EOF
}
test_func
So, now I get this error: other_func: command not found.
I don't want to create a file and put a function in it and then copy it in the remote machine and then call it there.
I also don't want to put my function inside here document.
In the above example variables in the local machine can be called in the remote machine, so how can I call a local function in a remote machine?
Why doesn't EOF understand a function call in a remote machine?
So, I got it resolved by adding this line "$(declare -f other_func); export -f other_func" just after ubuntu#xx.xx.xx.xx
Because the remote shell created by ssh has no access to variables or functions created on the machine where you run ssh, any more than it can read files on the server where you run ssh from within that ssh session. Anything local you want to make available on the remote machine needs to be copied there, one way or another.
With a function which you only need to execute on the remote machine, trivially put it in the here document.
ssh user#remote <<____EOF
other_func() {
c='This is it'
# backslash required inside here doc
# quoting should be fixed outside here doc, too
echo "\$c"
}
other_func
____EOF
For a function you want both locally and remotely, maybe put it in a separate file and copy it over somehow.
# make func available locally
. path/to/func_def
ssh user#remote <<____EOF
# make func available remotely
$(cat path/to/func_def)
# and call it
other_func
____EOF
Inlining the function like this is pretty obscure, though; perhaps better to simply scp the file to a standard location on every server where you need it.
I'm trying to execute the command "file /directory/*" through the web, using Ajax that call a perl script.
When I'm running the script from the server I get the mime type correctly, but when i'm using the web that trigger the ajax, i'm getting "application/x-empty".
If i'm running the command from the server using "sudo -u apache perl_script.pl" - the result is correct.
Why from the Ajax I get a different response ?
Try without the asterisk but instead with a complete filename.