JMeter + Grafana: How to Use Grafana to Monitor JMeter
July 6, 2021

JMeter + Grafana: How to Use Grafana to Monitor JMeter

Open Source Automation

Using Grafana and JMeter together allows you to easily monitor JMeter non-GUI results. 

Back to top

Overview: JMeter + Grafana

Using Apache JMeter™ in non-GUI mode is a useful way to run your load tests, because it takes less machine resources and is quicker. But if you want to monitor these results, you have to use different tools.

In the previous article about JMeter monitoring in non-GUI mode, we covered three ways to easily verify real-time execution of JMeter performance scripts: with out-of-the-box logs, with Taurus and with BlazeMeter.

This time we are going to cover one more way, by using Grafana. This way requires installation of InfluxDB and Grafana. Grafana is an open-source platform for time series analytics, which allows you to create real-time graphs based on time series data. InfluxDB is the time series database which is used as a temporary metrics storage.

As both these tools are designed for time series data, combined they are a wonderful solution for keeping and visualizing real-time performance metrics. That’s why, even though the installation steps might make this way the most complicated one, we highly recommend it. Grafana and InfluxDB provide some unique benefits, which can be very valuable.

First of all, Grafana allows you to store performance reports as long as you want. Grafana reporting is also very beneficial for those who already use InfluxDB and Grafana for other needs. Grafana is a pretty common solution for overall application monitoring. Many companies use Grafana dashboards metrics with the Amazon Cloudwatch integration, which also makes it a commonly used solution.

In addition to that, Grafana allows you to customize your dashboards in any way you want. So we can definitely say that integrating JMeter with Grafana is a reasonable way to monitor your performance scripts - a bit complicated on the one hand but pretty beneficial on the other.

Back to top

How Does Grafana Integrate With JMeter?

There are three steps to integrate JMeter with Grafana:

  1. Install and Configure InfluxDB
  2. Push Performance Metrics from JMeter to InfluxDB
  3. Monitor JMeter Performance Metrics in Grafana

 

1. Install and Configure InfluxDB

First of all, we need a JMeter performance script to test. We can use the same performance script we created in the previous article, which is run against the http://blazedemo.com/ web application. Or, use your own.

As soon as we have the performance script in place, we need to take care of the InfluxDB and Grafana installation. In this article we are going to cover the brief steps of installation based on OS X as a target platform, but you can easily find installation steps for your system by using the appropriate links provided in each step.

First of all, we need to install InfluxDB as a permanent storage space for our performance metrics. Grafana is a scalable datastore for time series metrics. Installation steps for all supported platforms can be found through this link. Installation on the OS X machine is very straightforward and can be done in just a few steps, if brew is installed on your machine. In this case you just need to run these two commands:

> brew update
> brew install influxdb

 

 

At the end of installation you should see this:

A screenshot of InfluxDB installation code.

InfluxDB is installed and can be run by these two commands:

> ln -sfv /usr/local/opt/influxdb/*.plist ~/Library/LaunchAgents
> launchctl load ~/Library/LaunchAgents/homebrew.mxcl.influxdb.plist

 

 

To verify that InfluxDB is up and running, all you need to do is to open a terminal window and run this command:

> influx

 

 

If the installation was completed successfully and the database is up and running, you will see an InfluxDB command line interface. This can be used for interacting with the database.

By using the ‘SHOW DATABASES’ command, you can see the list of all existing InfluxDB dabasebases. If you have just installed InfluxDB you should see only one ‘_internal’ database, which is used for keeping different stats about database itself:

A screenshot of the SHOW DATABASES command in InfluxDB.

At this point we can create a new database to store our performance metrics. For that you need to be logged in influx command line interface and run this command:

> CREATE DATABASE jmeter

 

 

After that you should see your newly created database, by using the same ‘SHOW DATABASES’ command we used in the previous step:

A screenshot of creating a JMeter database in InfluxDB.

Once we have created a database for our metrics, we need to make a few changes to the InfluxDB configuration. Use this reference to find the location of the configuration file, based on your system. In the OS X system, the configuration file is located at this location:
 

>vim/usr/local/etc/influxdb.conf


In this configuration file you need to find, uncomment and edit the ‘[[graphite]]’ category appropriately:

[[graphite]]
  # Determines whether the graphite endpoint is enabled.
  enabled = true
  database = "jmeter"
  retention-policy = ""
  bind-address = ":2003"
  protocol = "tcp"
  consistency-level = "one"
  batch-size = 5000
  batch-pending = 10
  batch-timeout = "1s"
  udp-read-buffer = 0
  separator = "."

 

After that you need to restart InfluxDB by applying an edited configuration:
 

> influxd -config /usr/local/etc/influxdb.conf

 

To confirm the configuration was applied successfully, you should find this line during the InfluxDB startup:

 

A screenshot of InfluxDB startup.

Congratulations! We have completed the first step of our long road to establish an integration of JMeter with Grafana monitoring. Now it’s time to push the metrics into the database we created.
 

2. Push Performance Metrics from JMeter to InfluxDB

To push performance metrics from JMeter to InfluxDB, we need to use the Backend Listener.  This listener enables writing metrics directly to the database.

Let’s add the Backend Listener to our performance script:

 

A screenshot of the JMeter backend listener.

Configure the Backend Listener:

 

A screenshot of how to configure the backend listener in JMeter.

 

Backend Listener Implementation

This is an implementation class that will be used as a listener for JMeter test metrics. The value for this parameter is based on the protocol we are going to use. If you remember, we used the graphite protocol configuration specified to the InfluxDB configuration. For this we need to use the ‘GraphiteBackendListenerClient’.

Async Queue Size

The queue value contains metrics for when they are processed asynchronously. It is better not to change this value from the default ‘5000’ value, unless have some specific performance issues.

graphiteMetricsSender

The implementation class that will be used as the metrics sender. Just use the default.

graphiteHost

The host where InfluxDB is located.

graphitePort

The port we specified in the ‘graphite’ section of InfluxDB configuration file.

rootMetricsPrefix

The basic prefix that will be used for all metrics stored in the database. Keep in mind that the metrics do not have a default separator. This is why it is better to use the ‘.’ symbol at the end of the prefix specified in this property.

summaryOnly

Use ‘true’ if you want to keep summary results only in the database and do not want to collect all the detailed metrics during test execution.

samplersList

Use this field if you want to send specific samplers only to the database. In our case, we want to send all samples, so we will leave this parameter blank.

useRegexpForSamplersList

Put ‘true’ if you want to specify a regexp in the ‘samplersList’ field to choose the samplers that should be sent to database.

percentiles

This is used to specify the metrics percentiles that should be send to database.

Once the configuration is in place, we can run our test execution.

After the test execution is completed, we can check the InfluxDB and verify that our metrics were reported there successfully. To do so, open the InfluxDB command line interface again and use this command:
 

> influx
> USE jmeter
> SHOW MEASUREMENTS
> SELECT * FROM “jmeter.all.a.avg”

 

We should find metrics with a timestamp and an appropriate value:

 

A screenshot of a timestamp in InfluxDB.

 

Now that we see that all metrics were reported successfully from JMeter to InfluxDB, we are ready for out the last step - visualize reported metrics using Grafana.
 

3. Monitor JMeter Performance Metrics in Grafana

 

First of all, let’s install Grafana on our local machine. Installation steps based on your system can be found through this link. For OS X the installation is very similar to the InfluxDB installations steps. Installation can also be performed via the brew package manager:
 

> brew install grafana

 

And another one to start the service:

> brew services start grafana


After that, Grafana should be available on http://localhost:3000. Use ‘admin’ as a default username and password to log in.

 

A screenshot of Grafana login.


First of all, we need to specify the data source with our metrics. Click on “Add data source” on the welcome page:

 

A screenshot of Grafana dashboard.


On the next page put the appropriate configuration based on our previous steps, and click on the “Add” button to verify that Grafana can connect to InfluxDB:

 

A screenshot of editing a data source in Grafana.


Now we can create our first dashboard in Grafana. Open the Grafana menu by clicking on the top left button and go to Dashboards -> New:

 

A screenshot of creating a new Grafana dashboard.

 

I would definitely recommend going over Grafana documentation to understand the main principles and to learn how to create detailed graphs for different needs. You can use this link as an intro step.

 

But to explain briefly, you can create different dashboards and specify multiple rows that represent time series metrics, in each dashboard. Grafana takes the data from InfluxDB which was collected there from JMeter. By clicking on the top of each row, you can choose which metric that row should represent.

 

A screenshot of configuring JMeter charts in a Grafana dashboard.

Grafana enables you to customize your metrics and graphs in any way you want. This  makes it very flexible for your needs. You can combine all the useful information into one dashboard and use it for real-time monitoring of your performance scripts.

In addition, since all metrics are stored on your server database, you can keep these metrics forever and create performance patterns analysis during your next test executions. Just add more graphs. This will ensure you’re on top of JMeter monitoring!

 

A screenshot of JMeter response time in Grafana dashboard.

 

Back to top

Next Steps for JMeter + Grafana

Congratulations! You now know how to monitor JMeter non-GUI results with Grafana. 

To learn JMeter, check out our BlazeMeter University.

This blog was originally published on July 5, 2017 and has since been updated for accuracy and relevance.

START TESTING NOW

 

Related Resources

Back to top