With JMeter or any performance testing-tool, one can see the detailed error logs only after the test run completes.
Suppose you have a development team monitoring the test or a stakeholder demanding to know why a particular request or API failed during a test. In that case, you will not have an answer unless you have had time to analyze the test results (which testing tools post after the test). It’s more real for headless test-runs such as non-GUI executions wherein the test logs such as View Results Tree/Summary Table cannot be accessed.
Wouldn’t it be great to have this information handy during the test, to dynamically view test results such as transactions that are slow with detailed error data in real-time?
An easy way to discern this is to have a non-relational database, like influx DB, record the real-time test logs into a table and plot it using a graphing tool, like Grafana. As long as the database connects to the graphing tool, one can view the historical and real-time data in terms of charts and graphs.
Not just you, but whoever has access to Grafana can view this information without any prior JMeter or performance testing knowledge
Tools Required for the set-up
- Time-Series Database like Graphite, Prometheus or Influx DB. I will be using influx DB for this article
- Graphing Tool: Grafana
- Testing Tool: Apache JMeter
Time Required to set-up: ~30 minutes
- Installed JMeter (https://jmeter.apache.org/download_jmeter.cgi : Pick the latest binary)
- JAVA latest version is configured in the system
- Windows machine, but can be done on Linux/MAC
Step 1: Setting up Influx DB
I. Download Software
Download influx DB from their official page : https://portal.influxdata.com/downloads/
Once the file is saved in the Downloads Folder, unzip it and the installation is complete
II. Configure the DB
Under Downloads, navigate to the Influx DB folder and you should see the influxdb.conf file in Windows Explorer window
III. Start Influx DB
To initiate the database, lets launch the Command Prompt by clicking CTRL +R; Type cmd
Navigate(cd) to the path where the influxDB exe files are present in the downloads folder
Execute the below command to initiate the db server.
influxd.exe -config influxdb.conf and click ENTER
IV. Create Database
Open a new command line window. Navigate to the influx DB path, and type influx.
If the server started successfully in the previous step, you should now see the version and a message that you are connected to the localhost at port 8086 which is configured by default during the installation.
Play with the below influx command to see the existing databases.
Ø Show databases : to see the existing databases
To proceed, create a database that you would like to use for the Grafana project. Lets call it ‘demo’
Ø Create database demo
Ø Use demo
You can query to check if the table was created
> Show databases
> show measurements
> select * from jmeter
Step 2: Setup Grafana
I. Download Grafana
Download the software from Grafana’s official web site. https://grafana.com/docs/grafana/latest/installation/windows/
Follow the installation steps
The Grafana backend has a number of configuration options defined in the config file (usually located at /etc/grafana/grafana.ini on linux systems).
In this config file you can change things like the default admin password, http port, grafana database (sqlite3, mysql, postgres), authentication options (google, github, ldap, auth proxy) along with many other options.
II. Start the Server
Start your Grafana server by executing the Grafana-server.exe from the command line interface
III. Launch Grafana in Browser
The Port on which the tool is listening at is 3000 by default. Browse the URL to http://localhost:3000/login
Grafana is configured to work with admin user
Credentials: User: admin; Pwd: admin
Note: Change the Password after the first login
IV. Add Data Source
Click on the Configuration Settings on the side menu and head to Data Sources
Click on Add your data source
Select the InfluxDB in the list of Databases provided
In the settings Page, enter the below details
URL : localhost or IP address where the InfluxDB server is running
Once done, Click on Save and Test. It should pop up a Connection successful.
V. Grafana Dashboard set up
To create dashboards, one can either start from the scratch or utilize the existing json templates by importing them from the world wide web. For either of them, the first step is to click on Create New Dashboard from the menu
For ease of set up, we will look into utilizing an excellent dashboard template provided by grafana Labs.
Download the json template @https://grafana.com/grafana/dashboards/5496
For more reading on sample dashboards, visit https://grafana.com/grafana/
We have multiple ways to feed the JSON template to Grafana.
- Browse to the JSON template downloaded in the previous step
- Import via grafana.com by keying in the template # 5496
This completes the necessary set up for both influx DB and Grafana. The last remaining configuration is at the testing tool — JMeter
Step 3: Backend Listener setup at JMeter
I. Backend Listener for Influx DB
Launch an existing .jmx script in JMeter or create a new script with at least one HTTP Sample pointing to a website : https://google.com
Right click on the Thread Group, and select Backend Listener from the Listeners sub section
Once included, open it and Select the Influx DB Backend Listener from the Backend Listener Implementation:
- influxdbMetricsSender(Default): org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender
- InfluxdbURL(Customize the database name give at InfluxDB) : If it’s your machine where the InfluxDB setup is being done then use localhost otherwise use the IP address of the machine where the Influx DB server is installed and initiated.Make sure the database name is correctly key in
- Remaining fields to be entered at your preference
- Application: The applicationundertest_env name to be seen in the Grafana dashboard (Provide environment when testing multiple environments)
- Measurement(this field value should match with Grafana Dashboard set up — default value): jmeter
- Test title: The name of the test like LoadTest, SmokeRun etc.
Before starting the test, ensure grafana-server.exe and influx are running from their root folders
influxd.exe -config influxdb.conf
Now begin the JMetest by running a simple load test against the application under test.
You should see influx DB writing the jmeter measurements into the ‘demo’ database
At this point, as a final step — Launch Grafana in the browser (http://localhost:3000) and traverse to the Dashboard.
The test requests are updated in the Dashboard where live-monitoring and tracking can be done.
datasource mapped to InfluxDB from the Grafana Add Data Source Configuration
Application mapped to the Backend Listener — Application name
Error Details on the Go:
My test did not have any failures, but if yours do, the transactions or request URLs will be displayed here along with the error rate and the HTTP status code in real-time during the test.
Written originally for PerfMatrix: https://www.perfmatrix.com/jmeter-grafana-dashboard-using-influxdb/
PerfMatrix is an excellent repository if you are an aspiring Performance test engineer and also if you are in the industry for long to refer to interesting articles on the go.
If you are keen, you can even share your learnings as a Guest contributor to PerfMatrix for benefitting larger audience.