DEV Community

Cover image for Jmeter load test with real time dashboard(InfluxDB)
Watcharin(start)
Watcharin(start)

Posted on

Jmeter load test with real time dashboard(InfluxDB)

🤖 Hey there! Just wanted to give you a quick update. Right now, I'm working on setting up a way to test how well our app performs. We're building a web app for our customers, so making sure it works smoothly is a big deal. We're using a user-friendly interface to create different performance test scenarios. The idea is to show how the app holds up under different conditions.

To do this, we're using JMeter to create scripts that simulate a bunch of people using the app at once. The only catch is that JMeter doesn't create fancy comparison reports for our customers. It mostly gives us raw data and documentation-style reports. So, I've come up with a plan. We're going to hook up InfluxDB to help us store performance data in a way that's easy to understand. Later on, we'll turn this data into cool visual dashboards.

Setting up

  1. Develop a docker-compose into workspace

    ---
    version: '3.8'
    
    volumes:
      influx-data:
    
    networks:
      dev:
    
    services:
      influxdb:
        image: influxdb:2.7-alpine
        container_name: influxdb
        restart: unless-stopped
        ports:
          - 8086:8086
        networks:
          - dev
        volumes:
          - influx-data:/var/lib/influxdb2
          - ./influxdb2/conf:/etc/influxdb2
      demo-app:
        image: go-example:1.0 # build from my local app
        container_name: go-app
        ports:
          - 3000:3000
        networks:
          - dev
    

    You can replace demo-app with your app

  2. Provide docker compose with docker-compose up

  3. Verify application is available with cURL

    $ curl localhost:3000/healthz
    OK%
    
  4. Then open web browser to config InfluxDB http://localhost:8086

    InfluxDB welcome page

  5. Create a user to manage InfluxDB

    Init admin user

  6. Save a token for access database via API and select configure later. Finish!!

    First token for admin

  7. Now, we’re already to collect data from Jmeter

Create a Jmeter script

You can develop your own scenarios like below

Jmeter scenarios

In the last step of your script, you add backend listener to InfluxDB.

Jmeter backend listener

Or you can add this XML to your JMX file.

...
                <BackendListener guiclass="BackendListenerGui" testclass="BackendListener" testname="Influxdb" enabled="true">
          <elementProp name="arguments" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" enabled="true">
            <collectionProp name="Arguments.arguments">
              <elementProp name="influxdbMetricsSender" elementType="Argument">
                <stringProp name="Argument.name">influxdbMetricsSender</stringProp>
                <stringProp name="Argument.value">org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="influxdbUrl" elementType="Argument">
                <stringProp name="Argument.name">influxdbUrl</stringProp>
                <stringProp name="Argument.value">http://localhost:8086/api/v2/write?org=start&amp;bucket=jmeter</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="application" elementType="Argument">
                <stringProp name="Argument.name">application</stringProp>
                <stringProp name="Argument.value">demo-go</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="measurement" elementType="Argument">
                <stringProp name="Argument.name">measurement</stringProp>
                <stringProp name="Argument.value">jmeter</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="summaryOnly" elementType="Argument">
                <stringProp name="Argument.name">summaryOnly</stringProp>
                <stringProp name="Argument.value">false</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="samplersRegex" elementType="Argument">
                <stringProp name="Argument.name">samplersRegex</stringProp>
                <stringProp name="Argument.value">.*</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="percentiles" elementType="Argument">
                <stringProp name="Argument.name">percentiles</stringProp>
                <stringProp name="Argument.value">90;95;99</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="testTitle" elementType="Argument">
                <stringProp name="Argument.name">testTitle</stringProp>
                <stringProp name="Argument.value">Test simple</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="eventTags" elementType="Argument">
                <stringProp name="Argument.name">eventTags</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="influxdbToken" elementType="Argument">
                <stringProp name="Argument.name">influxdbToken</stringProp>
                <stringProp name="Argument.value">NykJl8CX4paZEN3q7yNnIs9F_mLlnpITDWnWyfDSDv4yTyx6y0JOTMbExQljc_sq1qBVEYl5r4FFW3_NJd9SmQ==-7IV6tg8MsuwYU-5l4UyrtA==</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
            </collectionProp>
          </elementProp>
          <stringProp name="classname">org.apache.jmeter.visualizers.backend.influxdb.InfluxdbBackendListenerClient</stringProp>
        </BackendListener>
...
Enter fullscreen mode Exit fullscreen mode

Import InfluxDB dashboard

InfluxDB provide a web service that you can import a dashboard template on it.

  1. Go to InfluxDB web UI
  2. Go to Dashboard >> Click Create Dashboard >> Add a Template
  3. Parse a YAML file URL into block number 2(You can copy URL here)
  4. Click Lookup Template >> Install template
  5. After finish you can see a dashboard on your page

InfluxDB dashboard

Execute load test

After you prepare your workspace, Let’s start your Jmeter script to test your application.

Then, you can see realtime result on your dashboard.

load test metrics

Conclusion

Enhance your load testing experience by seamlessly integrating your testing tools with a visualization platform, allowing you to create insightful dashboards that display real-time results of your testing scenarios. For this purpose, I've employed a widely recognized tool, JMeter, which conveniently offers a plugin for seamless integration with InfluxDB.

I'm optimistic that my upcoming workshop will prove invaluable in enhancing your testing journey. Looking forward to sharing knowledge and boosting your testing prowess. 🤖👾

Top comments (0)