JMeter Apache for testing your web app

April 12, 2020


1. Install jmeter and run it

sudo apt install jmeter

In my case, openjdk version was in version 10.0.2 that it wasn't compatible with jmeter. I had to downgrade it:

java -version
sudo apt-get remove openjdk-*
sudo apt-get install openjdk-8-jre
java -version


2. Create your tests

A good introduction to create your tests is in jmeter's documentation



3. Install jmeter in your AWS EC2 server

After installing jemeter succesfully on the server we won't need to connect again. The following script will copy and then run the tests using ssh connection, and then download the results so we can visualize them on our local machine.


4. Run the script

Add in the same folder of your jmeter tests this script, set the variables with yours and run it. Note that ~/ path should be used with $HOME/ in a bash script.


# jmeter_ec2 - A script to run jmeter tests from ec2 instance

# set variables

echo $key_path

echo "coping test file to EC2"
scp -i "$key_path" $test_path $ec2_user@$public_dns:jmeter_ec2_tmp.jmx

# make test file writable, so can be overwritten later with scp
ssh -i "$key_path" $ec2_user@$public_dns 'chmod +w jmeter_ec2_tmp.jmx'

# run test in cli mode
ssh -i "$key_path" $ec2_user@$public_dns 'jmeter -n -t jmeter_ec2_tmp.jmx -l jmeter_ec2_tmp.csv' &
echo "testing..."

# copy the results to your computer
sudo scp -i "$key_path" $ec2_user@$public_dns:jmeter_ec2_tmp.csv $results_path

echo "Test finished and results are saved."