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.
How to Integrate JMeter with Grafana
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:
At the end of installation you should see this:
InfluxDB is installed and can be run by these two commands:
To verify that InfluxDB is up and running, all you need to do is to open a terminal window and run this command:
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:
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:
After that you should see your newly created database, by using the same ‘SHOW DATABASES’ command we used in the previous step:
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:
In this configuration file you need to find, uncomment and edit the ‘[[graphite]]’ category appropriately:
After that you need to restart InfluxDB by applying an edited configuration:
To confirm the configuration was applied successfully, you should find this line during the 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.
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:
Configure the Backend Listener:
- 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 - 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:
We should find metrics with a timestamp and an appropriate value:
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.
Monitoring 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:
And another one to start the service:
After that, Grafana should be available on http://localhost:3000. Use ‘admin’ as a default username and password to log in.
First of all, we need to specify the data source with our metrics. Click on “Add data source” on the welcome page:
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:
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:
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.
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!
Congratulations! You now know how to monitor JMeter non-GUI results with Grafana. To start testing and analyzing with BlazeMeter, just put your URL or JMX file in the box below and your test will start in minutes.
To learn JMeter, check out our free JMeter academy.
You might also find these useful:
Interested in writing for our Blog? Send us a pitch!