Skip to main content

Grafana Dashboards

Grafana provides powerful visualization capabilities for k6 test results. By combining k6 metrics with application and system metrics in a single dashboard, you can quickly identify performance bottlenecks and analyze trends over time.

Benefits

Visualizing k6 results in Grafana offers several advantages:

Real-Time Monitoring

Watch test results as they stream in, identifying issues immediately

Historical Analysis

Compare test runs over time to track performance trends

Correlation

View k6 metrics alongside system metrics (CPU, memory) to find root causes

Customization

Create dashboards tailored to your specific needs and metrics
Grafana dashboard showing k6 results correlated with system metrics

Prerequisites

To visualize k6 results in Grafana, you need:
  1. Grafana - Either self-hosted or Grafana Cloud
  2. Storage backend - A database to store k6 metrics (InfluxDB, Prometheus, etc.)
  3. k6 output configuration - Stream metrics from k6 to your backend

Quick Start

Here’s a complete example using Docker Compose with InfluxDB and Grafana:
1

Create docker-compose.yml

docker-compose.yml
version: '3.8'
services:
  influxdb:
    image: influxdb:2.7
    ports:
      - "8086:8086"
    environment:
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=admin
      - DOCKER_INFLUXDB_INIT_PASSWORD=adminpass
      - DOCKER_INFLUXDB_INIT_ORG=myorg
      - DOCKER_INFLUXDB_INIT_BUCKET=k6
    volumes:
      - influxdb-data:/var/lib/influxdb2

  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"
    environment:
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    volumes:
      - grafana-data:/var/lib/grafana
    depends_on:
      - influxdb

volumes:
  influxdb-data:
  grafana-data:
2

Start services

docker-compose up -d
3

Build k6 with InfluxDB extension

xk6 build --with github.com/grafana/xk6-output-influxdb
4

Run k6 test

K6_INFLUXDB_ORGANIZATION=myorg \
K6_INFLUXDB_BUCKET=k6 \
K6_INFLUXDB_TOKEN=your-token \
./k6 run --out xk6-influxdb script.js
5

Access Grafana

Open http://localhost:3000 and import a pre-built dashboard

Pre-Built Dashboards

Several k6 outputs include ready-to-use Grafana dashboards:
Output: grafana/xk6-output-influxdbDashboards:
  • k6 Test Result Dashboard
  • k6 Test Comparison Dashboard
Import:
  1. Download dashboards from GitHub
  2. In Grafana: Dashboards → Import → Upload JSON file
  3. Select your InfluxDB data source
Features:
  • Real-time metrics visualization
  • Request rate and error rate
  • Response time percentiles
  • Virtual user activity
  • Data transfer rates

Dashboard Examples

Standard Metrics Dashboard

A typical k6 dashboard includes these panels: Performance Overview:
  • Response time (p50, p95, p99)
  • Request rate (requests/second)
  • Error rate (%)
  • Virtual users (active)
HTTP Metrics:
  • Request duration breakdown (blocked, connecting, TLS, sending, waiting, receiving)
  • Failed requests over time
  • Requests by status code
System Impact:
  • Data sent/received
  • Iterations per second
  • Iteration duration
Thresholds & Checks:
  • Threshold violations
  • Check success rate

Correlation Dashboard

Combine k6 metrics with application metrics:
┌─────────────────────────────────────────────────┐
│ k6 Response Time (p95)          │ CPU Usage (%) │
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │ ━━━━━━━━━━━━ │
└─────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ k6 Request Rate        │ Database Connections   │
│ ━━━━━━━━━━━━━━━━━━━━ │ ━━━━━━━━━━━━━━━━━━━━ │
└─────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ k6 Error Rate          │ Application Logs       │
│ ━━━━━━━━━━━━━━━━━━━━ │ [ERROR] Connection...│
└─────────────────────────────────────────────────┘
This allows you to:
  • Identify when high load causes CPU spikes
  • Correlate response time degradation with database saturation
  • Match error rates with application errors

Creating Custom Dashboards

Build dashboards tailored to your specific needs:
Response time percentiles:
from(bucket: "k6")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "http_req_duration")
  |> aggregateWindow(every: 10s, fn: mean)
Request rate:
from(bucket: "k6")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "http_reqs")
  |> derivative(unit: 1s, nonNegative: true)
Error rate:
from(bucket: "k6")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "http_req_failed")
  |> map(fn: (r) => ({ r with _value: r._value * 100.0 }))

Best Practices

  • For live tests: Last 5-15 minutes
  • For analysis: Full test duration
  • For trends: Days or weeks
Set refresh interval to 5-10 seconds for real-time monitoring.
Create dashboard variables for:
  • Test run ID or tag
  • Scenario name
  • Environment (dev, staging, prod)
This makes dashboards reusable across different tests.
Mark important events on your graphs:
  • Deployment times
  • Configuration changes
  • Threshold violations
Use Grafana’s annotation features or log them as metrics.
Configure alerts for:
  • Error rate exceeds threshold
  • Response time degradation
  • Test failures
Send notifications to Slack, PagerDuty, or email.

Complete Example

Here’s a full workflow with InfluxDB and Grafana:
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '1m', target: 10 },
    { duration: '3m', target: 10 },
    { duration: '1m', target: 0 },
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'],
    http_req_failed: ['rate<0.01'],
  },
};

export default function () {
  const res = http.get('https://test.k6.io');
  check(res, {
    'status is 200': (r) => r.status === 200,
    'response time < 500ms': (r) => r.timings.duration < 500,
  });
  sleep(1);
}

Grafana Cloud k6

For a fully managed solution, Grafana Cloud k6 provides:
  • Automatic metric storage and retention
  • Pre-built dashboards optimized for k6
  • Test management and scheduling
  • Team collaboration features
  • Cloud execution for distributed tests
  • No infrastructure to manage
Grafana Cloud k6 includes specialized views beyond standard Grafana dashboards, designed specifically for load testing workflows.

Community Dashboards

Explore more dashboards created by the community:

Next Steps

Real-Time Streaming

Learn how to stream metrics to your backend

Web Dashboard

Use the built-in k6 web dashboard

Grafana Docs

Explore Grafana’s documentation

InfluxDB Extension

View the InfluxDB output extension

Build docs developers (and LLMs) love