Distributed Load Testing In JMeter Using Docker



INDEX:

I )    WHY DOCKER?

II) WHAT  IS DOCKER?

III)    DOCKER TERMILOGIES:

IV)   INSTALLATION OF DOCKER:

V)     USE OF DOCKER FOR DISTRIBUTED TESTING IN JMETER (MASTER AND SLAVE):

VI)   DOCKER SETUP FOR JMETER:

  1. Run the test using Jmeter Master container only (Non distributed Mode) using Master container on same aws machine
  2. Run the test using Jmeter Master and slave container on same aws machine (Distributed Mode) 
  3. Distributed testing on different AWS machines (Master and Slave on 2 different aws machines)

VII)    INFLUXDB and GRAFANA SETUP ON MASTER SLAVE MACHINE FOR ANALYSIS AND MONITORING JMETER TEST

VIII)   MISCELLANEOUS


1. Why Docker:

  1. Docker is a simple way to deploy and run software applications. 
  2. Docker provides you with lightweight isolated containers that behave like a virtual machine, but at the same time share the OS where they have been run 
  3. In comparison with virtual machines, Docker allows you to spin up lots of isolated dockers without any additional resources cost. 





2. WHAT  IS DOCKER?

  1. Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel.
  2. Efficient utilization of hardware system along with Configuration and settings are easy in docker.
  3. Build shift and deploy docker image anywhere concept is used.


3. DOCKER TERMILOGIES:


  1. Docker Hub: Docker image repository as docker hub

  2. Docker Image: Docker image is a group of layers.

    1. (For Eg while running a test we will require multiple layers to execute in sequence like 1st layer installation of JDK,2nd Layer installation of JMeter version,3rd layer environment setup).

    2. To ease installation and configuration setup we use a docker image.

Refer: qautomation.blog/2019/05/07/top-docker-images-for-performance-testers/

  1. Docker Container: Running of the image is called docker container

  2. Docker File : A text document with commands necessary to assemble an image. When using Docker it’s not mandatory to handle a Dockerfile, because you can use the image directly if you have one.

  3. Docker engine - A sort of minimalistic operating system where virtualized applications are executed. 


4. INSTALLATION OF DOCKER:

  • hub.docker.com/editions/community/docker-ce-desktop-windows





5. USE OF DOCKER FOR DISTRIBUTED TESTING IN JMETER (MASTER AND SLAVE):




What Docker has to offer for Apache JMeter? 

  1. To do distributed load testing – we need 1 master & we need N number of slaves to generate a huge load. 
  2. With every new installation of Apache JMeter, you need to download/install JMeter on every new node participating in Distributed Load Testing. Installing JMeter requires dependencies to be installed first like JAVA,  
  3. With Docker, it is just a matter of 1 Docker Compose file and a one-liner command to get the entire infrastructure ready. 
  4. Each and every JMeter slave machine needs to have a specific version of Java and JMeter installed.
  5.  Specific ports should be opened and the JMeter server should be running, ready, and waiting for the master to send the instruction.
  6. Setting up a few machines manually might look easy. What if we have to do this for 50, 100, 1000 machines? Also, imagine what will happen if we need to upgrade JMeter versions in all the machines in the future!! That is where docker comes into the picture.
  7. We basically set up the whole infrastructure for JMeter distributed testing in a file called Dockerfile.

VI) DOCKER SETUP FOR JMETER:

 #Pre condition 

  1. Aws EC2 instance machine which needs to be used for Master and Slave in distributed testing
  2. Docker must be installed in the respective server aws machine
  3. Git Bash should be installed in local machine to connect server aws machines 

Run tests on one server(Master-Slave on same machine IP different)


STEPS:

1.We have created 2 EC2 instances (virtual box in the cloud) in aws:

Master:10.23.14.197         Slave:10.23.15.9

NOTE:

[root@ip-10-23-14-197 ~]# =>Server root directory where docker container is run.

[ec2-user@ip-10-23-14-197 ~]$ =>Server User to (login)

root@ee36aff04836=>Docker Root container (where we run JMeter commands)


2.Copy private key file from downloads to the current directory. Then run below the “ssh” command to login.

(Dist-test.pem is a private key file generated while creating machines on ec2 (virtual box) in aws.)

root@DEVOPS-LAP-07:/mnt/c/Users/ssonawane/Downloads# cp dist-test.pem ~/

3. “ssh” command will give access to aws ec2 instance

root@DEVOPS-LAP-07:~# ssh -i dist-test.pem ec2-user@10.23.14.197


4.To remove the above warning “UNPROTECTED PRIVATE KEY FILE” change permissions of “dist-test.pem” private key file using chmod below command

root@DEVOPS-LAP-07:~# chmod 400 dist-test.pem

5.Re-run ssh command and now our instance is running.

root@DEVOPS-LAP-07:~# ssh -i dist-test.pem ec2-user@10.23.14.197

6.Install Docker on aws instances using commands

[root@ip-10-23-14-197 ~]# yum install docker

7.Check Docker version and verify docker installation

[root@ip-10-23-14-197 ~]# docker version


8.We will receive the below error message after running the command Docker version 

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

9.To start docker and remove above error run below systemctl commands (Start ) and check status 

[root@ip-10-23-14-197 ~]# systemctl start docker

[root@ip-10-23-14-197 ~]# systemctl status docker

10.Copy “testdocker.jmx” script from local to root directory of server machine

root@DEVOPS-LAP-07:~# scp -i dist-test.pem  /mnt/c/Users/ssonawane/Desktop/Jmeter/Final/apache-jmeter-5.1.1/apache-jmeter-5.1.1/bin/testdocker.jmx  ec2-user@10.23.14.197:~/

testdocker.jmx                                                                        100%   14KB  50.6KB/s   00:00


11.To Switch to root machine of ec2 machine use command “sudo -i”

[ec2-user@ip-10-23-14-197 ~]$ sudo -i


12.To Obtain a Docker image there are 2 ways :

  1. First is to create a docker image from the docker file 

  2. The second is to pull a docker image from docker hub


13.To pull inbuilt JMeter docker images(Master image,slave image,Jmeter Base image) from docker hub 

[root@ip-10-23-14-197 ~]# docker pull mnazim1541/jmbase

[root@ip-10-23-14-197 ~]# docker pull mnazim1541/jmmaster

[root@ip-10-23-14-197 ~]# docker pull mnazim1541/jmslave

OR


Note: To Create a docker image use the below commands:

  • Change to the directory where the docker file resides.

  • Filename should be “Dockerfile”.


Command to create docker image:


 docker build -t <Name of Image> . 

 Eg:docker build -t JmeterBase .   


13.Create Master & Slaves Containers on the Same Machine.

Run the below commands to create the containers by running the respective images.  (Run n number of times below command to generate n slaves) 

[root@ip-10-23-14-197 ~]# docker run -dit –name master mnazim1541/jmmaster /bin/bash 

[root@ip-10-23-14-197 ~]# docker run -dit --name slave01 mnazim1541/jmslave /bin/bash


14.To check docker images run the command:

[root@ip-10-23-14-197 ~]# docker images



15.Run Docker ps command to list all running containers 

[root@ip-10-23-14-197 ~]# docker ps -a



16.Run the below command to get the list of ip addresses for these containers.(Use GIT Bash to execute below command)(IP ‘s will be required for running slave machine)

[root@ip-10-23-14-197 ~]# docker inspect --format '{{ .Name }} => {{ .NetworkSettings.IPAddress }}' $(docker ps -a -q)


17. Go inside the Master container with the below command and we can see all the files after pulling image on machine

[root@ip-10-23-14-197 ~]# docker exec -it master /bin/bash

root@ee36aff04836:/# ls

JMeterFiles  bin  boot  dev  docker-java-home  etc  home  JMeter  lib  lib64 media  mnt  opt  proc  root  run  sbin  srv  sys  mp  usr  var


18.**********************Copy Scripts & jmeter files to container**************** 


To move the script from local machine to aws machine run below command (using private key file “dist-test.pem” of aws ec2 instance.


root@DEVOPS-LAP-07:~# scp -i dist-test.pem  /mnt/c/Users/ssonawane/Desktop/Jmeter/Final/apache-jmeter-5.1.1/apache-jmeter-5.1.1/bin/Dockerblazedemo.jmx   ec2-user@10.23.14.197:~/ 


Dockerblazedemo.jmx 100%   14KB  50.9KB/s   00:00


Once the script is moved from local to aws machine.Copy script in docker container JmeterFiles folder


[root@ip-10-23-14-197 ~]# docker cp /home/ec2-user/Dockerblazedemo.jmx ee36aff04836:/JMeterFiles/

[root@ip-10-23-14-197 ~]# ls

JMeterFiles  base


19.Run docker exec command to check script is copied to the container


[root@ip-10-23-14-197 ~]# docker exec -it master /bin/bash

JmeterFiles

root@ee36aff04836:/# cd JmeterFiles


root@ee36aff04836:/JMeterFiles# ls


BLAZEMETER_TestResults_301219063432.jtl  Dockerblazedemo.jmx      INPRO_QuickSearch.jmx     INPRO_Users_Credentials.csv  jmeter.log

BlazemeterDemo_Test_Script.jmx           INPRO_AdvanceSearch.jmx  INPRO_SearchTestData.csv  Result.jtl                  testdocker.jmx


    • SCENARIO 1:

20.Now we are ready and start jmeter test with below command (Non distributed test):

************** Run the test on Jmeter Master only (Non distributed Mode)*************** 

root@ee36aff04836:/JMeterFiles# jmeter -n -t Dockerblazedemo.jmx -l results.jtl

Creating summariser <summary>

Created the tree successfully using Dockerblazedemo.jmx

Starting the test @ Mon Dec 30 06:52:24 UTC 2019 (1577688744895)

Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445

summary =      1 in 00:00:02 =    0.6/s Avg:    75 Min:    75 Max:    75 Err:     0 (0.00%)

Tidying up ...    @ Mon Dec 30 06:52:27 UTC 2019 (1577688747316)

... end of run


SCENARIO 2:

21..Run the below command to run the test in distributed using docker containers. (Different IP addresses of all the slaves machine) 

*********** Run the test on Jmeter Master and slave on same aws machine (Distributed Mode)****************** 


root@ee36aff04836:/JMeterFiles# jmeter -n -t Dockerblazedemo.jmx -R 172.17.0.3 -l slave.jtl

root@ee36aff04836:/JMeterFiles# jmeter -n -t Dockerblazedemo.jmx -R 172.17.0.3 -l TestResults1.jtl

Creating summariser <summary>

Created the tree successfully using Dockerblazedemo.jmx

Configuring remote engine: 172.17.0.3

Starting remote engines

Starting the test @ Mon Dec 30 13:50:14 UTC 2019 (1577713814354)

Remote engines have been started

Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445

summary =      1 in 00:00:01 =    1.0/s Avg:    77 Min:    77 Max:    77 Err:     0 (0.00%)

Tidying up remote @ Mon Dec 30 13:50:16 UTC 2019 (1577713816993)

... end of run



22.********** Copy the generated result file from container to local system**************


 


[root@ip-10-23-14-197 ~]# pwd

/root

[root@ip-10-23-14-197 ~]#

[root@ip-10-23-14-197 ~]# ls -lrt

total 4

drwxr-xr-x 2 root     root      24 Dec 30 05:33 base

drwxr-xr-x 2 root     root      28 Dec 30 06:17 JMeterFiles

-rw-r--r-- 1 root     root       0 Dec 30 12:30 172.17.0.3

-rw-r--r-- 1 ec2-user ec2-user 580 Dec 30 13:50 TestResults1.jtl

[root@ip-10-23-14-197 ~]# pwd

/root

[root@ip-10-23-14-197 ~]# logout

[ec2-user@ip-10-23-14-197 ~]$ ls -lrt /root

ls: cannot open directory /root: Permission denied

[ec2-user@ip-10-23-14-197 ~]$ sudo -i

[root@ip-10-23-14-197 ~]# pwd

/root

[root@ip-10-23-14-197 ~]# ls -lrt

total 4

drwxr-xr-x 2 root     root      24 Dec 30 05:33 base

drwxr-xr-x 2 root     root      28 Dec 30 06:17 JMeterFiles

-rw-r--r-- 1 root     root       0 Dec 30 12:30 172.17.0.3

-rw-r--r-- 1 ec2-user ec2-user 580 Dec 30 13:50 TestResults1.jtl

[root@ip-10-23-14-197 ~]# cp TestResults1.jtl /home/ec2-user/

cp: overwrite ‘/home/ec2-user/TestResults1.jtl’? y

[root@ip-10-23-14-197 ~]# cd /home/ec2-user/

[root@ip-10-23-14-197 ec2-user]# ls -lrt

total 36

-rwxrwxr-x 1 ec2-user ec2-user 14699 Dec 30 05:24 testdocker.jmx

-rwxrwxr-x 1 ec2-user ec2-user 14699 Dec 30 06:36 Dockerblazedemo.jmx

drwxrwxr-x 2 ec2-user ec2-user     6 Dec 30 06:48 JmeterFiles

-rw-r--r-- 1 ec2-user ec2-user   580 Dec 30 15:04 TestResults1.jtl

[root@ip-10-23-14-197 ec2-user]# chmod 777 TestResults1.jtl

[root@ip-10-23-14-197 ec2-user]# logout

[ec2-user@ip-10-23-14-197 ~]$ logout

Connection to 10.23.14.197 closed.

root@DEVOPS-LAP-07:~#                                                                                                                         100%  580     2.0KB/s   00:00

root@DEVOPS-LAP-07:~# ls -lrt

total 128

drwxrwxrwx 1 root root   512 Sep 26 19:51 shraddha

-rw-rw-r-- 1 root root 11002 Nov 13 18:07 commands.txt

-rw-rw-r-- 1 root root 10920 Nov 13 18:10 commands2.txt

-rw-rw-r-- 1 root root 24468 Nov 20 16:57 Grafana_ResponseSheet_1500usesr_2011.ods

-rw-rw-r-- 1 root root  3359 Nov 20 16:58 1500Users_Capitalone_2011_ErrorDetail.txt

-rwxrwxr-x 1 root root 68604 Dec 19 18:24 CapitalOneLoadTesting__STG_2019.jmx

-r-------- 1 root root  1692 Dec 30 10:26 dist-test.pem

-rwxrwxrwx 1 root root   580 Dec 30 20:35 TestResults1.jtl

root@DEVOPS-LAP-07:~# cp TestResults1.jtl /mnt/c/Users/ssonawane/Desktop/

root@DEVOPS-LAP-07:~#


Step1:

Login to machine:

root@DEVOPS-LAP-07:~# ssh -i dist-test.pem ec2-user@10.23.14.197

Last login: Mon Dec 30 15:16:01 2019 from ip-10-32-50-88.us-west-2.compute.internal


       __|  __|_  )

       _|  (     /   Amazon Linux 2 AMI

      ___|\___|___|


https://aws.amazon.com/amazon-linux-2/

8 package(s) needed for security, out of 17 available

Run "sudo yum update" to apply all updates.

[ec2-user@ip-10-23-14-197 ~]$


Step2:

Check recent file with all permissions using ls -lrth:


[ec2-user@ip-10-23-14-197 ~]$ ls -lrth

total 36K

-rwxrwxr-x 1 ec2-user ec2-user 15K Dec 30 05:24 testdocker.jmx

-rwxrwxr-x 1 ec2-user ec2-user 15K Dec 30 06:36 Dockerblazedemo.jmx

drwxrwxr-x 2 ec2-user ec2-user   6 Dec 30 06:48 JmeterFiles

-rwxrwxrwx 1 ec2-user ec2-user 580 Dec 30 15:04 TestResults1.jtl

-rwxrwxrwx 1 ec2-user ec2-user   0 Dec 30 15:16 scripts.sh

-rw-rw-r-- 1 ec2-user ec2-user   0 Dec 30 15:24 Finaltext.txt


Step3:

Check current directory path

[ec2-user@ip-10-23-14-197 ~]$ pwd

/home/ec2-user


Step4:Since ec2 user have all access,change owner of file to ec2 user using chown 

chmod 777 (give all permission to ec2)

[root@ip-10-23-14-197 ec2-user]# chmod 777 Finaltext.txt or chown ec2-user. Finaltext.txt

[root@ip-10-23-14-197 ec2-user]# ls -lhrt

total 36K

-rwxrwxr-x 1 ec2-user ec2-user 15K Dec 30 05:24 testdocker.jmx

-rwxrwxr-x 1 ec2-user ec2-user 15K Dec 30 06:36 Dockerblazedemo.jmx

drwxrwxr-x 2 ec2-user ec2-user   6 Dec 30 06:48 JmeterFiles

-rwxrwxrwx 1 ec2-user ec2-user 580 Dec 30 15:04 TestResults1.jtl

-rwxrwxrwx 1 ec2-user ec2-user   0 Dec 30 15:16 scripts.sh

-rwxrwxrwx 1 ec2-user ec2-user   0 Dec 30 15:42 Finaltext.txt


Step5:

Logout from ec2 and root directory of ec2

[root@ip-10-23-14-197 ec2-user]# logout

[ec2-user@ip-10-23-14-197 ~]$ logout


Step6:

Copy file from aws server to root of local machines

root@DEVOPS-LAP-07:~# scp -i dist-test.pem ec2-user@10.23.14.197:~/Finaltext.txt .

Finaltext.txt                                                                                                                             100%    0     0.0KB/s   00:00


Step7:

Copy file from root of local machine to desktop

root@DEVOPS-LAP-07:~# cp Finaltext.txt /mnt/c/Users/ssonawane/Desktop

root@DEVOPS-LAP-07:~# ls -lrth

total 128K

drwxrwxrwx 1 root root  512 Sep 26 19:51 shraddha

-rw-rw-r-- 1 root root  11K Nov 13 18:07 commands.txt

-rw-rw-r-- 1 root root  11K Nov 13 18:10 commands2.txt

-rw-rw-r-- 1 root root  24K Nov 20 16:57 Grafana_ResponseSheet_1500usesr_2011.ods

-rw-rw-r-- 1 root root 3.3K Nov 20 16:58 1500Users_Capitalone_2011_ErrorDetail.txt

-rwxrwxr-x 1 root root  67K Dec 19 18:24 CapitalOneLoadTesting__STG_2019.jmx

-r-------- 1 root root 1.7K Dec 30 10:26 dist-test.pem

-rwxrwxrwx 1 root root  580 Dec 30 20:35 TestResults1.jtl

-rwxrwxrwx 1 root root    0 Dec 30 20:51 scripts.sh

-rwxrwxrwx 1 root root    0 Dec 30 21:18 Finaltext.txt

root@DEVOPS-LAP-07:~#





    • SCENARIO 3:

Distributed testing on different AWS machines:

Ref:https://hub.docker.com/r/thothbot/jmeter-master/ 


To execute test on different aws machines we need to first do port opening in aws console:









In AWS, we need to add below rules for port opening in below Master and Slave machines:


Master IP address:10.23.14.197/32

Slave IP Address: 10.23.15.9/32



First, we need to open ports from Master to connect slave:1099,50000

Then we need to open ports from Slave to connect master:60000



# Master node setup


1.# Login to a remote server 


bjarwal@DEVOPS-LAP-05:~$ cd ssh-keys/

bjarwal@DEVOPS-LAP-05:~/ssh-keys$ ssh -i dist-test.pem ec2-user@10.23.14.197

Last login: Tue Dec 31 11:08:42 2019 from ip-10-32-50-88.us-west-2.compute.internal


       __|  __|_  )

       _|  (     /   Amazon Linux 2 AMI

      ___|\___|___|


2.#Switch to the root user

[ec2-user@ip-10-23-15-9 ~]$ sudo -i



3.# Make directory

[root@ip-10-23-14-197~]# mkdir -p jmeter-master/JmeterFiles


4.# Now go to jmeter-master/JMeterFiles directory and copy your jmeter scripts



[root@ip- 10-23-14-197 ~]# cd jmeter-master/JmeterFiles/


5.#Copy script from local machine root to aws machine root-Master(10-23-14-197):


root@DEVOPS-LAP-07:~# scp -i dist-test.pem /mnt/c/users/ssonawane/Desktop/testdocker.jmx ec2-user@10.23.14.197:~/

testdocker.jmx                                                                                                 100%   14KB  50.8KB/s   00:00


6.#Check copied file on aws machine Master using “ls” command

[ec2-user@ip-10-23-14-197 ~]$ ls

Dockerblazedemo.jmx  Finaltext.txt  testdocker.jmx JmeterFiles  TestResults1.jtl  scripts.sh  testdocker.jmx


7.#Now copy  script from aws machine Master root to   jmeter-master/JmeterFiles folder

[ec2-user@ip-10-23-14-197 ~]$ pwd

/home/ec2-user

[ec2-user@ip-10-23-14-197 ~]$ sudo -i

[root@ip-10-23-14-197 jmeter-master]# cd JMeterFiles

[root@ip-10-23-14-197 JMeterFiles]# cp -v /home/ec2-user/IntegrationDockerJmeter.jmx  .

‘/home/ec2-user/IntegrationDockerJmeter.jmx’ -> ‘./IntegrationDockerJmeter.jmx’



OR


[root@ip-10-23-14-197 JMeterFiles]# cp -v ../../JMeterFiles/testdocker.jmx .

‘../../JMeterFiles/testdocker.jmx’ -> ‘./testdocker.jmx’


8.#Change directory jmeter-master

cd ..


9#  Copy jmeter-master Dockerfile into jmeter-master directory and build image

[root@ip-10-23-14-197 jmeter-master]# vi Dockerfile (Copy Dockerfile in jmeter-master folder)

[root@ip-10-23-14-197 jmeter-master]# docker build -t jmeter-master .


Successfully built 6ada2e11e068

Successfully tagged JMeter-master: latest


{Note:To Remove unwanted containers use prune command

[root@ip-10-23-14-197 ~]# docker system prune -a   }


10#.To check whether docker image is created run below command 

[root@ip-10-23-14-197 jmeter-master]# docker images

REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE

jmeter-master                  latest              6ada2e11e068        9 seconds ago       311MB

11.Run below commad to Create container using Docker master image

[root@ip-10-23-14-197 ~]# docker run -dit -p 60000:60000 --name master01 jmeter-master /bin/bash

aaec0f61d8abf5ca05b011a5d21af80f5c363bf114818803cbe285752843c3c6


12.Check whethetr container is generated using “docker ps “ commands

[root@ip-10-23-14-197 ~]# docker ps

CONTAINER ID        IMAGE                          COMMAND                CREATED             STATUS              PORTS                      NAMES

aaec0f61d8ab        jmeter-master                  "/bin/bash"            4 seconds ago       Up 3 seconds        0.0.0.0:60000->60000/tcp   master01


13.#Login to docker container from where we need to execute jmeter test

root@ip-10-23-14-197 ~]# docker exec -it aaec0f61d8ab /bin/bash

root@aaec0f61d8ab:/# ls -ltr

total 0

drwxr-xr-x   2 root root   6 Nov 10 12:17 home

drwxr-xr-x   2 root root   6 Nov 10 12:17 boot

drwxr-xr-x   1 root root  41 Dec 24 00:00 var

drwxr-xr-x   1 root root  41 Dec 24 00:00 usr

drwxr-xr-x   2 root root   6 Dec 24 00:00 srv

drwxr-xr-x   3 root root  30 Dec 24 00:00 run

drwxr-xr-x   2 root root   6 Dec 24 00:00 opt

drwxr-xr-x   2 root root   6 Dec 24 00:00 mnt

drwxr-xr-x   2 root root   6 Dec 24 00:00 media

drwxr-xr-x   2 root root  34 Dec 24 00:00 lib64

drwxr-xr-x   1 root root  30 Dec 28 08:57 lib

drwx------   1 root root  24 Dec 28 08:57 root

dr-xr-xr-x  13 root root   0 Dec 31 07:57 sys

drwxrwxrwt   1 root root   6 Jan  2 04:37 tmp

drwxr-xr-x   1 root root  63 Jan  2 04:37 sbin

drwxr-xr-x   1 root root  44 Jan  2 04:37 bin

drwxr-xr-x   3 root root  31 Jan  2 04:37 jmeter

drwxr-xr-x   2 root root  28 Jan  2 04:37 JMeterFiles

drwxr-xr-x   1 root root  66 Jan  2 05:21 etc

dr-xr-xr-x 112 root root   0 Jan  2 05:21 proc

drwxr-xr-x   5 root root 360 Jan  2 05:21 dev


14.# Go to JMeterFiles directory

cd JMeterFiles

root@aaec0f61d8ab:/# cd JmeterFiles/


15.# Run jmeter test


root@aaec0f61d8ab:/JMeterFiles# jmeter -n -t testdocker.jmx  -Djava.rmi.server.hostname=10.23.14.197 -Dclient.rmi.localport=60000 -R 10.23.15.9


Parameters:

-n => non gui mode

-t => jmx script

- Djava.rmi.server.hostname =>Master machine ip

-Dclient.rmi.localport=60000 => Port to connect Slave machine (10,23,15.9)

-R 10.23.15.9 => Slave ip machine


Output:

Creating summariser <summary>

Created the tree successfully using testdocker.jmx

Configuring remote engine: 10.23.15.9

Starting remote engines

Starting the test @ Thu Jan 02 05:22:55 UTC 2020 (1577942575865)

Remote engines have been started

Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445

summary =      1 in 00:00:01 =    1.1/s Avg:    65 Min:    65 Max:    65 Err:     0 (0.00%)

Tidying up remote @ Thu Jan 02 05:22:58 UTC 2020 (1577942578251)

... end of run






# SLAVE NODE SETUP


16.#  Login to remote server of Slave Machine and Switch to root user

    sudo -i


17.# Make directory on Slave machine

root@ip-10-23-15-9 ~]# mkdir -p jmeter-slave/JmeterFiles


[root@ip-10-23-15-9 ~]# cd jmeter-slave/JMeterFiles/

[root@ip-10-23-15-9 JMeterFiles]# cd ..

[root@ip-10-23-15-9 jmeter-slave]# ls -ltrh

total 0

drwxr-xr-x 2 root root 6 Jan  2 04:39 JMeterFiles



18.# Copy JMeter-slave Dockerfile into JMeter-slave directory and build image


[root@ip-10-23-15-9 jmeter-slave]# vi Dockerfile  (Copy dockerfile in jmeter-slave folder)

[root@ip-10-23-15-9 jmeter-slave]# ls -ltrh

total 4.0K

drwxr-xr-x 2 root root    6 Jan  2 04:39 JMeterFiles

-rw-r--r-- 1 root root 1.1K Jan  2 04:40 Dockerfile


[root@ip-10-23-15-9 jmeter-slave]# docker build -t jmeter-slave .   (Build image)

Successfully built b13f7e871217

Successfully tagged jmeter-slave:latest


19.# Run below commad to start container of slave

[root@ip-10-23-15-9 jmeter-slave]# docker run -dit --name slave03 -e LOCALIP='10.23.15.9' -p 1099:1099 -p 50000:50000 jmeter-slave /bin/bash

f0c3546494640f14b370bfacd21effd07cd038eb5b32da7474e3e6e263f8acc5


Parameters in command:

-i =>starts an interactive session and

-t=>emulates a tty. 

-d=>tells Docker to detach and run in the background. 

 --name slave => name of containers

-e LOCALIP='10.23.15.9' 

-p 1099:1099 => first port stands for host port : second port is for container port

jmeter-slave ==>docker slave image

/bin/bash==> shell is assigned




20.To check whether slave container is generated  run docker ps command

[root@ip-10-23-15-9 jmeter-slave]# docker ps

[root@ip-10-23-15-9 jmeter-slave]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                         NAMES

f0c354649464        jmeter-slave        "/bin/sh -c 'jmeter-…"   3 seconds ago       Up 2 seconds        0.0.0.0:1099->1099/tcp, 0.0.0.0:50000->50000/tcp, 60000/tcp   slave03


20# When the test is started we can Check container live logs on the Slave machine using the below command: docker logs -f slave01


To check logs on Slave machine we need container id of slave machine:


[root@ip-10-23-15-9 jmeter-slave]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                         NAMES

f0c354649464        jmeter-slave        "/bin/sh -c 'jmeter-…"   3 seconds ago       Up 2 seconds        0.0.0.0:1099->1099/tcp, 0.0.0.0:50000->50000/tcp, 60000/tcp   slave03


[[root@ip-10-23-15-9 jmeter-slave]# docker logs -f f0c354649464


Using local port: 50000

Created remote object: UnicastServerRef [liveRef: [endpoint:[10.23.15.9:50000](local),objID:[-7804db79:16f64aea323:-7fff, -8824373264067557367]]]



Starting the test on host 10.23.15.9 @ Thu Jan 02 05:16:18 UTC 2020 (1577942178696)

Finished the test on host 10.23.15.9 @ Thu Jan 02 05:16:21 UTC 2020 (1577942181161)

Starting the test on host 10.23.15.9 @ Thu Jan 02 05:19:44 UTC 2020 (1577942384406)

Finished the test on host 10.23.15.9 @ Thu Jan 02 05:19:45 UTC 2020 (1577942385370)

Starting the test on host 10.23.15.9 @ Thu Jan 02 05:22:57 UTC 2020 (1577942577308)

Finished the test on host 10.23.15.9 @ Thu Jan 02 05:22:58 UTC 2020 (1577942578251)






VII) JMeter Dashboard – Grafana/InfluxDB using Docker: 

Lightweight integration of Grafana and InfluxDB, by using the Docker technology that can be used for monitoring and storing the test metrics of your performance scripts 

  • Jmeter is a widely used open-source tool for testing but it lacks one feature that is analyzing performance test during execution 

  • One of the solution is to use Grafana and InfluxDB.

    1. Grafana is an open-source platform for time series analytics, which allows you to create real-time graphs based on time series data.

    2. InfluxDB is the time series database that is used as a temporary metrics storage.

  • We had used two different containers. The first container runs Grafana for showing dashboards, while the second one runs InfluxDB for storing metrics.

  • Docker Compose is designed to combine multiple dockers in one standalone composition, which you can run through one command. This is very convenient when you need to run different containers together in integration 

  • In our case, we need to run two different applications (Grafana and InfluxDB) and that's why it makes sense 



Prerequisites

In order to use the prepared docker file, you need to have the following installed:

  • Docker – to spin up the containers with InfluxDB and Grafana. Installation steps here.

  • Docker Compose – to integrate the InfluxDB and Grafana containers together and have just one script to rule them all


STEPS:

Step1) Open the Console and Login to Aws Master machine

root@DEVOPS-LAP-07:~# ssh -i dist-test.pem ec2-user@10.23.14.197

[root@ip-10-23-14-197 ~]# less /etc/os-release

Step 2) Install Git on Aws machine

[root@ip-10-23-14-197 ~]# yum install git


Step 3) Download GrafanaInfluxDocker from Git Repo on Master machine

[root@ip-10-23-14-197 ~]# git clone https://github.com/QACodeDev/GrafanaInfluxDocker.git

Cloning into 'GrafanaInfluxDocker'...

remote: Enumerating objects: 13, done.

remote: Counting objects: 100% (13/13), done.

remote: Compressing objects: 100% (12/12), done.

remote: Total 13 (delta 0), reused 13 (delta 0), pack-reused 0

Unpacking objects: 100% (13/13), done.


Under this Repo, will find influx and grafana docker files and dockercompose yml file




[root@ip-10-23-14-197 ~]# ls

172.17.0.3        Dockerfile   Finaltext.txt        JMeterFiles       base           jmeterbase    scripts.sh

DockerScript.jmx  Dockerfile1  GrafanaInfluxDocker  TestResults1.jtl  jmeter-master  jmetermaster




[root@ip-10-23-14-197 ~]# cd GrafanaInfluxDocker


[root@ip-10-23-14-197 GrafanaInfluxDocker]# ls

README.md  configuration.env  docker-compose.yml  grafana  influxdb

[root@ip-10-23-14-197 GrafanaInfluxDocker]#



Step 4)Install Docker compose using curl command (or https://docs.docker.com/compose/install/ )

  • In order to run the containers using Docker compose, you need to run this command from the main folder where the docker-compose.yml is located .In case “ GrafanaInfluxDocker”


  • This command will spin up Grafana and InfluxDB integrated together.  


  • [root@ip-10-23-14-197 ~]# curl -L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   617    0   617    0     0   2328      0 --:--:-- --:--:-- --:--:--  2328

100 16.2M  100 16.2M    0     0  6188k      0  0:00:02  0:00:02 --:--:-- 7997k


Step 5) Run Docker -compose command

 To run the docker compose in background mode, you need to pass the additional argument '-d 

[root@ip-10-23-14-197 GrafanaInfluxDocker]# docker-compose up -d


After few minutes. If you see a similar output then you are good:



To stop the containers you can run the command: 




Step 6:For Influxdb setup,we need to add Backend Listener in Jmeter script     for communication between jmeter and influxdb



Parameters that need to be modified:


  • Enter influxdb url (Machine ip where influxdb is hosted)and Influxdb name

influxdbUrl

http://10.0.75.1:8086/write?db=jmeterdocker2

  • Give Application name to be monitored

application

dockerapp1

  • Give database table name in measurement section 

measurement

jmeter

  • Summary needs to be set  false


 Step 7: In order to run InfluxDB queries, you need to login inside the         InfluxDB docker  container 


  •    root@DEVOPS-LAP-07:~# ssh -i dist-test.pem ec2-user@10.23.14.197

   Last login: Thu Jan  2 05:58:18 2020 from ip-10-32-50-88.us-west-2.compute.internal


  • (Note:dist-test.pem is a private key file which needs to be passed as a parameter to login aws         machine)



  • First, you need to get the list of all docker containers running. Use this specified command and find the container ID related to the InfluxDB container (it should have the 'influxdb' string inside the container name): 


[root@ip-10-23-14-197 ~]# docker ps

CONTAINER ID        IMAGE                          COMMAND                CREATED             STATUS              PORTS                      NAMES

aaec0f61d8ab        jmeter-master                  "/bin/bash"            39 minutes ago      Up 39 minutes       0.0.0.0:60000->60000/tcp   master01

e87df66db3bf        grafanainfluxdocker_grafana    "/app/entrypoint.sh"   42 hours ago        Up 41 hours         0.0.0.0:3000->3000/tcp     grafanainfluxdocker_grafana_1

519f48028084        grafanainfluxdocker_influxdb   "/app/entrypoint.sh"   42 hours ago        Up 41 hours         0.0.0.0:8086->8086/tcp     grafanainfluxdocker_influxdb_1





  • Next to connect influx run the below command inside the influx container with the corresponding container id:





[root@ip-10-23-14-197 ~]# docker exec -it 519f48028084 influx

Connected to http://localhost:8086 version 1.3.1

InfluxDB shell version: 1.3.1




If everything is right,we can now execute influx db commands as below:



[root@ip-10-23-14-197 ~]# docker exec -it 519f48028084 influx

Connected to http://localhost:8086 version 1.3.1

InfluxDB shell version: 1.3.1

> create database jmeterdocker2; (///Create Database)

> show databases (//Show all database created)

name: databases

name

----

influx

_internal

jmeterdocker2

> use jmeterdocker2 (//Use command to select created db for influx

Using database jmeterdocker2

> show measurements (//Show measurements is same as show tablename)

name: measurements

name

----

events

jmeter

> select * from jmeter (//select command to see all statistics during test)

name: jmeter

time                application avg                count countError endedT hit max maxAT meanAT min minAT pct90.0            pct95.0            pct99.0            startedT statut transaction

----                ----------- ---                ----- ---------- ------ --- --- ----- ------ --- ----- -------            -------            -------            -------- ------ -----------

1578046683386000000 dockerapp1                                      0              0     0          0                                                              0               internal

1578046688370000000 dockerapp1  144.09999999999997 30    0                 70  680              64        367.50000000000045 576.5999999999999  680                         all    all

1578046688372000000 dockerapp1  71.1               10                          86               64        85.8               86                 86                          all    logout










Step 8: Start Load test from  Master and Slave docker container

root@aaec0f61d8ab:/JMeterFiles# jmeter -n -t RND_DockerGrafana.jmx -l testdocker3.jtl -Djava.rmi.server.hostname=10.23.14.197 -Dclient.rmi.localport=60000 -R 10.23.15.9


Master


Check logs on Slave machine



Step 9: Once the test is started, all JMeter test result data starts getting stored in influxdb which we can check under measurement “Jmeter”.

Run Show measurement command and you will be able to see stats like min,max,avg,error count



























Step 10:To view Influxdb Db stats in a readable format and in graphical format with real live dashboards we used the Grafana tool.


  • Using url <Machine IP >:<Port no> ,we can access Grafana from any browser

<Machine ip> = IP address of Master machine 10.23.14.197

<Port no> =80


Step 11:To Access Grafana URL from different aws machines, we need to create rules for those particular IP source machines to communicate over port 80. 


Here Source machines were:10.32.50.88 and 10.32.50.75


Grafana URL:<Master Machine chine IP> :<Commuincation Port>   =>10.23.14.197:8-0



Step 12:For communication of Grafana and influxdb ,Add default influxdb data source in grafana 


  • Add data source in grafana and select “Infludb” type and provide url of influxdb hosted achine 

  • Provide same influxdb database name which is given in jmeter backend listener







Step 12:Next Step,To create Dashboard to View jmeter test data stored in infludb during load test.


  • We have some inbuilt dashboards,to fetch them we need to import dashboard id “4026”



Provide dashboard name and select DB name





Step 13. Once we import the dashboard we will be able to see a very informative dashboard  providing all minute details like

a.Transaction name

b.Error Rate

c.Failed request

d.Response time

e.Throughput 


(Note: We can customize the dashboard if we don't want to import an inbuilt dashboard)









NOW YOU ARE READY TO ANALYSE AND MONITOR JMETER TEST LIVE 




MISCELLANEOUS:

I .To copy file on aws machine from local:


1.From local machine root to aws user

root@DEVOPS-LAP-07:~# scp -i dist-test.pem /mnt/c/Users/ssonawane/Desktop/RND_DockerGrafana.jmx ec2-user@10.23.14.197:~/

RND_DockerGrafana.jmx                                                                                                       100%   15KB  49.6KB/s   00:00


2.from user directory to root directory of aws machine

[root@ip-10-23-14-197 jmeter-master]#  cp /home/ec2-user/RND_DockerGrafana.jmx    .

[root@ip-10-23-14-197 jmeter-master]# ls

Dockerfile  JMeterFiles  RND_DockerGrafana.jmx



3.from root directory to docker containers


[root@ip-10-23-14-197 JMeterFiles]# docker cp RND_DockerGrafana.jmx aaec0f61d8ab:/JMeterFiles

[root@ip-10-23-14-197 JMeterFiles]# docker exec -it aaec0f61d8ab /bin/bash

root@aaec0f61d8ab:/# cd JMeterFiles/

root@aaec0f61d8ab:/JMeterFiles# ls -lrt

total 60

-rwxr-xr-x 1 root root 14699 Jan  2 04:33 testdocker.jmx

-rwxr-xr-x 1 root root 14698 Jan  2 06:28 IntegrationDockerJmeter.jmx

-rw-r--r-- 1 root root  9126 Jan  3 07:37 jmeter.log

-r-xr-xr-x 1 root root 14961 Jan  3 09:56 RND_DockerGrafana.jmx















THANK YOU

1 comment:

If you have any doubt or suggestion, please let me know

Powered by Blogger.