JMeter Apache for testing your web app
1. Install jmeter and run it
sudo apt install jmeter 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.
#!/bin/bash # jmeter_ec2 - A script to run jmeter tests from ec2 instance # set variables key_path="$HOME/.ssh/key.pem" public_dns="ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com" test_path="$HOME/path_to/mytest.jmx" results_path="$HOME/path_to/results_auto.csv" ec2_user="ubuntu" 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..." wait # 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."