Performance/Load Testing with k6 +InfluxDB + Grafana on Windows

Dhanuka Dulanjana
5 min readJul 20, 2022

--

What is Performance Testing?

Performance testing is the general name for tests that check how the system behaves and performs. Performance testing examines the responsiveness, stability, scalability, reliability, speed, and resource usage of your software. Before performance testing, it’s important to determine your system’s business goals, so you can tell if your system behaves satisfactorily or not according to your customers’ needs.

After running performance tests, you can analyze the number of virtual users, hits per second, errors per second, response time, latency, and bytes per second (throughput), as well as the correlations between them. Through the reports, you can identify bottlenecks, bugs, and errors, then decide what needs to be done.

There are many types of tests catered for different purposes in performance testing (Source: https://en.wikipedia.org/wiki/Software_performance_testing)

  • Load testing: basically, putting load on the system to see how it behaves.
  • Stress testing: load testing to find the maximum amount of load the system can handle.
  • Soak testing: load testing a system continuously and monitoring for memory leaks and behavior of the system.
  • Spike testing: load testing with sudden increase or decrease of the load.
  • Breakpoint testing: like stress testing, but incremental load is put on the system over time to see how it behaves.
  • Configuration testing: changing configuration to see how the system behaves under different configurations, under load.
  • Isolation testing: Isolating a fault domain and repeating the test to confirm the failure.
  • Internet testing: global load testing for big companies to see how to system behaves from different regions.

K6, Scripting, and Running

As we all know, k6 is a modern open-source load testing tool that provides an outstanding developer experience to test the performance of APIs and websites. It is a feature-rich and easy to use CLI tool with test cases written in ES6 JavaScript and support for HTTP/1.1, HTTP/2, and WebSocket protocols.

Here is my first k6 code “SampleGetAPI.js”

Once you have saved this script somewhere you can run it as follows:

k6 run SampleGetAPI.js

Now let’s move to InfluxDB and Grafana Dashboard,

Results visualization with InfluxDB and Grafana

InfluxDB is a time-series database built for the high-performance handling of time-stamped data. K6 provides an inbuilt method 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.

Data Flow

K6 write the real-time test results into Influx database and Grafana will read the data from influxdb and display it on its dashboard.

  1. Install InfluxDB on Windows :

Firstly you should download and install InfluxDB. you can do it here

Then open the bin folder and you can see the following folder structure:

To start InfluxDB server navigate to bin folder and double click the influxd.exe file and minimize it(Do not close). This will start the InfluxDB and appear something like this

The next step is to create a database. for this double click the influx.exe file. using the below commands you can create a new database.

show databases
create database <any name>
use <database name>

***after creating database , then minimize the influx.exe file

We are all set with InfluxDB. Let's move to configure Grafana.

2. Install Grafana on Windows :

Firstly you should download and install Grafana. you can do it here. To start the Grafana server navigate to bin folder and double click the grafana-server.exe file and minimize it(Do not close).

To ensure grafana has started and is working. Browse to http://localhost:3000

The default username/password is admin/admin but you can change it later. Once logged in you will be presented with the Home Dashboard. From here you can create data sources, manage users, create report dashboards, etc.

The first thing we need to do is create a data source to pull data from our InfluxDB. Click Add Data Source and the name should be any name,I have used “K6”, then Specify the url: http://localhost:8086 and the database should be InfluxDB database we created earlier: jmeter.

Instead of creating a fresh Dashboard in Grafana, we use the existing dashboard template available on grafana.com. We are going to choose K6 Load Testing Result Dashboard. You can download it here.

Then you should import the downloaded dashboard JSON file.

The name should be any name, the Folder should be General, UID should be any name and InfluxDB should be the data source that you created early.

So we are done with our Grafana setup. And time for Bingo!!!! Run the actual tests and see the results Runtime

Running K6 Test and See the Results on Dashboard

To run K6 script you should use the below command

k6 run --out influxdb=http://localhost:8086/jmeter SampleGetAPI.js***jmeter is the database name we created early inside InfluxDB

Now you can see your dashboard.

This actually completes our integration setup for K6 with InfluxDB and Grafana to view Real-time Metrics Results. I hope you will find this article helpful.

Thanks for reading!!

--

--