Written By: Swetha Pujari
This is a simple guide to set up JMeter Grafana Dashboard using InfluxDB which describes the step-by-step setup process.
With JMeter or any performance testing tool, one can see the detailed error logs only after the test run completes. If you have a development team monitoring the test or any stakeholder asks the reason on why a certain request/API failed, you will not have an answer unless you had time to analyze the test results (which testing tools post after the test is finished). It’s more true for a headless test run such as non-GUI executions where you can not access the ‘View Results Tree’ or ‘Summary Table’ during the test.
Wouldn’t it be great to have this information handy at any point of time during the test, to dynamically view test results such as slower transactions and detailed error information amongst API calls/requests in real-time?
An easy way to perceive this is to have a non-relational database, like influx DB, record the real-time test logs into a table and then use a graphing tool, like Grafana, to display the live data. As long as the database connects to the Graphing tool, one can view the historic as well as real-time data in terms of charts and graphs.
Not just you, but whoever has access to Grafana can view this information without any JMeter or performance testing-related knowledge.
Tools required for the set-up
- Any Time-Series Database: Example Graphite, Prometheus or Influx DB. I have used influx DB for this article.
- Graphing Tool: Open Source Grafana
- Testing Tool: Open Source Apache JMeter
Time required to set-up: 30 minutes
- Apache JMeter should be installed
- JAVA latest version should be configured in the system
- Windows OS machine
Steps to Set up Influx DB
Step 1: Download Influx DB Software
- Click to download (https://portal.influxdata.com/downloads/)
- Once the file is downloaded in the ‘Downloads’ Folder it means that installation is completed. It is as simple as JMeter installation.
- Under Downloads, navigate to the Influx DB folder and you should see the ‘influxdb.conf file’ in the Windows Explorer window. In my case the location is
Step 2: Start Influx DB
- Launch the Command Prompt (Windows+R; Type cmd)
- Navigate to the path where the executable file (.exe) of influx DB is present.
- Type the below command to initiate the DB server and click ‘Enter’
influxd.exe -config influxdb.conf
Step 3: Create Database
- Once the influx DB server starts, open another command line window.
- Navigate to the influx DB path, and type influx in cmd.
- You should see the connection status along with the version of the software.
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
- As the Database initiates showing version 1.7.9, proceed to create the table ‘demo’ by using the command Create database demo.
- Follow the below mandatory steps in the interactive influx screen, without these steps, you won’t be able to see the graph on Grafana.
- Show databases: To see the databases already loaded with the installation.
- create <DBName>: To create a new database as per your project. Example: create demo
- use <DBName>: To ensure influx DB writes the ‘jmeter’ (measurement) metrics to a project name that you specify instead of the default. Example: use demo OR use cadvisor
After creating the DB (demo), let’s execute the below queries and check the output. The queries should return the correct output.
> Show database
> Show measurements
Steps to Set-up Grafana
Step 1: Download Grafana
- Click to the below link:
- Click on ‘Download Grafana.’ link on ‘Install on Windows’ page
- Select the Grafana version and edition.
- Click ‘Download the installer’. In case you use any other operating system then select the OS and download the respective Grafana installer.
Step 2: Configure Grafana
- The Grafana backend has a number of configuration options defined in its 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. As a beginner, you can avoid this configuration for now.
Step 3: Start the server
- Starting your Grafana server is similar to the influx DB. Launch the Windows command prompt and navigate to the Grafana folder in the ‘Downloads’ folder. Then type start Grafana-server from the cmd.
Step 4: Open the Grafana UI in Browser
- As soon as the server initiates, you can launch Grafana in your choice of Browser. The tool listens to the port 3000>> http://localhost:3000/
Note: In future, if you decide to run the Grafana server on your machine or any other server machine, change the URL pointing to localhost to the IP address or computer name running the Grafana server.exe. For now, you can conveniently ignore this.
- Enter the credential (if you set then use them). For first-time login, use the default admin user (admin/admin)
Step 5: Add Data Source
An essential step for connecting Grafana with your database is to ‘Add Data Source’ for your Grafana to connect and retrieve information to display. For that purpose, you have to follow the below steps:
- From the home screen, click on the ‘Configuration’ (the gear icon) menu to the left and head to ‘Data Sources’ (the DB icon) to add the data source. Refer to the below snapshot:
- Click on the button ‘Add Data Source’ and select InfluxDB from the list of databases provided.
- In the settings page, enter the below details
- URL: localhost if you are configuring on your machine or the IP address of the machine where the InfluxDB server is running.
- Once the details are provided, Click on the button ‘Save and Test’.
- It should pop up a tiny Connection successful.
Step 6: Create your first Grafana Dashboard
It is simple to create a dashboard that pools data from the database and generates graphs and charts. There are two ways to do this: One is to click on ‘Create New Dashboard’ from the menu or for beginners, to download an existing JSON dashboard to begin with.
In this article, we will look at the latter approach.
- Download the JSON file into the Grafana folder from the site https://grafana.com/grafana/dashboards/5496
- To add a new Dashboard with a pre-existing JSON file, click on Import from the menu.
- Browse the JSON file as per your requirement and upload it by using the option ‘Upload JSON File’
- Select the data source as influx DB that you have configured in Step 1 and click on ‘Import’. Your dashboard will be ready for use.
For more information on sample dashboards and features -> visit https://grafana.com/grafana/
Now, you have done all the preliminary set-up for both Grafana and Influx DB, you can proceed to the Backend Listener configuration at JMeter
Steps to set up JMeter Backend Listener
Step 1: Backend Listener for Influx DB
Now, you are at the last stage of the set-up. If you have come this far, you are ready to taste the sweet victory.
The last step is for JMeter to relay the test logs to Influx DB. For this,
- open any JMX script in JMeter or create a new script with at least one HTTP Sampler pointing to a sample AUT or any dummy website for testing.
- Right-click the ‘Thread Group’ and select ‘Backend Listener’ from the ‘Listeners‘ subsection.
- Once the ‘Backend Listener’ gets added click on it.
- Select the Influx DB Backend Listener from the Backend Listener Implementation
- Customize and Enter the following details:
- influxdbMetricsSender: org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender
- InfluxdbURL : 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.
- Remaining fields to be entered at your preference
- Application: The application_env name to be seen in the Grafana dashboard (Provide environment when testing multiple environments)
- Measurement: jmeter
- Test title: The name of the test etc.
- Refer to the below screenshot for more information
- Start the test and open Grafana dashboard in the browser (http://localhost:3000/login). The test requests are updated in the Dashboard where live monitoring and tracking can be done. Now sit back and relish the results.