JMeter CLI Create Dashboard
Date Published: 09/30/2019
Apache JMeter is a load testing and performance measurement tool for web applications and services. It provides a very simple interface to simulate the multiple threads for heavy load. You can find a lot of introductory tutorials for JMeter but here I am specifically focusing on JMeter CLI, how to pass the arguments from CLI to JMeter test plan, why and how to generate the interactive HTML dashboard to analyze the result through a table and various charts.

Get the JMeter load Test and helping files from following Github Repository:

https://github.com/fullstackhub-io/JMeter-CLI-Load-Test-Dashboard

Introduction

Apache JMeter is a load testing and performance measurement tool for web applications and services. It provides a very simple interface to simulate the multiple threads for heavy load. You can find a lot of introductory tutorials for JMeter but here I am specifically focusing on JMeter CLI, how to pass the arguments from CLI to JMeter test plan, why and how to generate the interactive HTML dashboard to analyze the result through a table and various charts. 

Since this is not an introductory tutorial, a little prior knowledge would be helpful to follow the tutorial but I will definitely explain each and every step. 

Let's Start

  • Download the JMeter from http://apache.mirrors.tds.net//jmeter/binaries/apache-jmeter-5.1.1.zip and extract it anywhere in the system. (This is for Windows, for Mac or Linux please follow the installation instruction on the website)
  • We first will design the test plan in JMeter UI, parameterized the required variable and then run it through CLI. In your extracted Apache JMeter folder go to the bin folder, locate the jmeter.bat file and double click to run it. Your JMeter UI will be open after a few moments: 

  • Let's create a simple test plan with a single HTTP Request to google.com with multiple users. Write click on Test Plan in the left pane and select the option Add -> Threads (Users) -> Thread Group. Select the Thread Group and you would see its options on the right pane. Here you can select a number of threads, ramp-up time (after how many seconds/mins the new user should add in thread group), Loop Count (how many times the test plan should execute) and Duration (total test plan running time), etc. Enter options like the following, 10 threads in 10 seconds ramp-up periods with 5 loops count: 

  • Let's add the simple HTTP Request sampler. For testing, let's use the https://jsonplaceholder.typicode.com/todos RESTful API. Right-click on Thread Group in the left pane, select the option Add -> Sampler -> HTTP Request and setup the request as the following screenshot:

  • Next steps to create the listener for this HTTP request. Right-click on Thread Group, select the option Add -> Listener -> View Results Tree option. Cool, click on top ribbon green arrow or press the key Ctrl + R. You should successful request in green color:

  • So our basic test plan is ready since JMeter GUI takes a lot of resources by running Listeners, it is suggested to run the JMeter through the console. The JMeter console can also create the Dashboard with many Graphs, Charts, and tables that can provide great analysis experience for the test cases. That's next.
  • First let's define the variable instead of hard coding the number of threads, ramp-up period, etc. Right-click on Test Plan and select Add -> Config Element -> User Defined Variables. Select it and Enter the variables as follow:   
  • We defined three variables, you can definitely define as many variables as you want. The variable name is USERS and ${__P(users, 10)} tells us that from console we can pass the users paramter whereas 10 is the default value. The same goes for the rest of the variables.
  • Next, go to Thread Group and replace the hardcoded values with variables as follow:       
  • Now let's create a batch file and call the test plan (jmx) file with parameters, locate the article_jmeter.jmx file (or whatever name you gave to your test plan file). I placed this file in unzipped JMete -> bin folder where jmeter.batch file resides. 
  • In the apache-jmeter-5.1.1 -> bin, create a file article_testplan.bat file. You can create it anywhere but let's keep the things simple to avoid the long paths. 
  • Edit the newly created article_testplan.bat file and paste the following commands in it: 
@echo off

Setlocal EnableDelayedExpansion

set SAVESTAMP=%DATE:/=-%_%TIME::=-%

set SAVESTAMP=%SAVESTAMP: =%

set SAVESTAMP=%SAVESTAMP:,=.%

jmeter -n -t article_testplan.jmx -Jusers=5 -Jrampup_sec=30 -Jloop=2 -l aricle_testplan_%SAVESTAMP%.jtl -e -o aricle_testplan_dashboard_%SAVESTAMP%
  • In the above commands, we first are getting the system time and the only purpose is to uniquely name each JTL file and dashboard folder name. In the last line, we are calling the JMeter batch file and specifying the arguments i.e. test plan file name and each user-defined variable with -J prefix and values. At the end of the command, we are specifying the dashboard folder name. After creating the article_testplan.bat file. Double click on it to run, it will take few seconds. After finish, you would find the aricle_testplan_[CURRENT_DATETIME].jtl file and aricle_testplan_dashboard_[CURRENT_DATETIME] folder where [CURRENT_DATETIME] is current time when you are running the test plan. 
  • You can always import the JTL file in JMeter and see the summary of the result but the dashboard gives you much more detail. Go to the newly created dashboard folder and run the index.html. You would see dashboard and charts menus in the left panel. Just go through them, they are pretty self-explanatory (In other words, I don't want to explain them by googling lot of terms they used and copy-pasting here).   


Keywords: apacha jmeter tutorial, jmeter tutorial, jmeter cli, jmeter create dashboard, create dashboard in jmeter, pass the arguments from jmeter cli to test plan