Capture & Monitor JMeter metrics in real-time with InfluxDB & Grafana

The JMeter GUI is great for creating and debugging test plans, however, as I have mentioned in a previous post it is not recommended for running your actual test plan. JMeter is simply not designed to produce high loads in GUI mode, as it can consume a lot of resources and potential produce unreliable load test results. While it is recommended you run your actual test in CLI mode, this means you have to wait until the test is complete before you can see the results. While this might be okay for short tests but for longer running soak tests you might want to examine the results while the test is running. In this post, I will show you how this can be achieved using InfluxDB and Grafana.

The Tools

InfluxDB is a time-series database built for high-performance handling of time-stamped data.  JMeter provides a backend listener InfluxdbBackendListenerClient to write the data to InfluxDB. Grafana is an open-source metric analytics and visualization suite. It is most commonly used for visualizing time series data for infrastructure and application analytics.

Setting up InfluxDB

Simply download InfluxDB and unzip to your desired directory, for example, c:\jmeter\influxdb

  1. To start InfluxDB navigate to /bin directory and double click the influxd.exe. influxd
  2. We need to create a database for storing our JMeter load test data. In the /bin directory double click Influx.exe.
  3. Run the SHOW DATABASES command – this will give you a list of databases.
  4. Run the command: CREATE DATABASE jmeterresults
  5. Run SHOW DATABASES again and you should see your new database listed.influx_createdb
  6. We are done with Influxdb.

Setting up JMeter

For this demonstration, I will be using the JMeter test project from my previous post to show you how to configure the backend listener to write metrics to InfluxDB.

  1. Add a new backend listener to the thread group
  2. Change its name to InfluxDB Backend Listener
  3. In the Backend Listener Implementation dropdown select org.apache.jmeter.visualizers.backend.influxdb.InfluxdbBackendListenerClient
  4. Configure the parameters as follows:
    • influxdbMetricsSender – this is the class for sending metrics to InfluxDB. keep it as default.
    • influxdbUrl – this is the URL of InfluxDB is in the following format: http://%5Binfluxdb_host%5D:%5Binfluxdb_port%5D/write?db=%5Bdatabase_name%5D. As we have created the “jmetermetrics” database and we are running it on a local machine with a default port, then, in our case, the URL will be
    • application – we can store metrics from different applications under one database.
    • measurement – the name of the measurement that will be stored in InfluxDB. Use default ‘jmeter’.
    • summaryOnly – if you want to keep summary results in the database and do not want to collect all the detailed metrics during test execution set to ‘true’.
    • samplersRegexp – use the regexp expression to filter specific metrics which you want to store in a database. Use the default “.*” value if you want to store all your metrics.
    • percentiles – metrics percentiles that should be sent to the database.
    • testTitle – give your test a name.
    • eventTags – a list of tags which will be stored in the ‘events’ measurement of InfluxDB.InfluxDBBackendListener
  5. We are done with the Listener Setup.

Setting up Grafana

Grafana is an open-source metrics analysis and monitoring/visualization tool. It works really well with time series data like InfluxDB.

  1. Download Grafana and extract the zip to a directory of your choosing, for example, c:\jmeter\Grafana.
  2. Before running you will want to make some changes to the default configuration. Locate the following file /conf/sample.ini and copy it to /conf/custom.ini
  3. We will use this custom.ini to patch our changes. You should never change the defaults.ini file directly.
  4. Grafana by default is configured to use port 3000 if this port is already in use you may need to change it. Edit custom.ini uncomment http_port and modify the port.
  5. To start Grafana navigate to the /bin directory and run grafana-server.exe.
  6. Browse to http://localhost:3000grafana
  7. The default username/password is admin/admin this can be changed or during startup when prompted.
  8. Once logged in you will be presented with the Home Dashboard. From here you can create data sources, manage users, create report dashboards etc.grafana_homedashboard
  9. The first thing we need to do is create a data source to pull data from our InfluxDB. Click Add Data Source and choose InfluxDB as the data source type. Specify the url: http://localhost:8086 and the name of the influxdb database we created earlier: jmetermetrics. You can also configure other settings for authentication. Click Save & Test hopefully you should see the Data source is working.
  10. Next, we are going to need a dashboard. You could create one from scratch however, to get us up and running quickly we are going to import an existing dashboard.
  11. Click Add Dashboard to locate existing dashboard screen click the link Find Dashboards On From here you can browse and search for available dashboards. If you search for JMeter you will discover several available for displaying JMeter metrics. We are going to choose Apache JMeter Dashboard using Core InfluxdbBackendListenerClient by Philippe M. copy the dashboard ID: 5496.
  12. Switch back to Grafana and the create dashboard screen and click Import Dashboard enter the dashboard ID we copied 5496 and click Load.
  13. On the import dashboard screen you will be prompted for the following:
    • Name – specifiy the dashboard name
    • Folder – Grafana allows you to organize dashboards into folders.
    • DB name – select the InfluxDB data source we created in step 9
    • Measurement name – we will set this to ‘jmeter’ not it is the same measurement we defined when we setup the JMeter Listener and is the table in our InfluxDB database.
    • Backend send interval – this should match the JMeter property backend_influxdb.send_interval which default value is 5 seconds.importdashbaord5496
  14. Our dashboard will be displayed as you would expect with no data displayed as we’ve don’t have any tests running and there is no data in our InfluxDB.dashboard5496
  15. We are done with Grafana setup.

Running your Test

Now for the easy bit switch back to JMeter and start the test. We should start to see JMeter metrics appearing in your grafana dashboard after 5 seconds and automatically updating every 5 seconds until our load test completes.dashbaord5496_1dashbaord5496_2

One of the nice features with Grafana is that it provides several ways to manage the time ranges of the data being visualized. GrafanaRange

It also allows you to take snapshots and export dashboard so they can be easily compared or shared and lots of other neat features. I highly recommend checking it out.

We can also verify the data in our InfluxDB by querying our database using the Influx.exe command-line interface.

  1. You need to tell InfluxDB which database you want to use run the command ‘use jmetermetrics’
  2. Now you can query the database lets run a simple select statement to retrieve records in our jmeter run ‘SELECT * FROM jmeter’ InfluxDBData
  3. All our JMeter metrics are readily available for us to query and report on.

Additional Info

Happy Testing!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s