RousselTMLEARNING

Article · Grafana k6: load and performance testing

Observing a k6 test

1. Why export? #

The summary is not enough.

Seeing over time #

Available in: ✓ OSS ✓ Enterprise ✓ Cloud

Observing a load test
k6 curves and those of the system under test on the same dashboard.

The end-of-test summary gives global averages and percentiles. To understand when latency breaks down and why, you need to see k6 metrics over time, next to the CPU, database connections and traces of the system under test.

2. To Prometheus #

The remote write output.

Configuration #

# Prometheus doit accepter le remote write
prometheus --config.file=prometheus.yml --web.enable-remote-write-receiver
K6_PROMETHEUS_RW_SERVER_URL=http://localhost:9090/api/v1/write \
K6_PROMETHEUS_RW_TREND_STATS="p(95),p(99),avg,max" \
k6 run -o experimental-prometheus-rw --tag testid=release-2.4 script.js
Prometheus metricOrigin
k6_http_reqs_totalhttp_reqs counter
k6_http_req_duration_p95Statistic requested in TREND_STATS
k6_http_req_failed_rateFailure rate
k6_vusVirtual users
Good practice: With K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM=true, durations are sent as native histograms: any percentile can then be computed in Grafana.
Good to know: The testid tag distinguishes runs: it lets you compare two tests in the same dashboard. Grafana publishes an official « k6 Prometheus » dashboard to import.

With OpenTelemetry #

k6 also has an OpenTelemetry output (-o opentelemetry) that sends its metrics over OTLP to a Collector or to Alloy, handy if your stack is already OTLP.

3. Correlating with the system under test #

Explaining the results.

Method #

  1. Mark the test: testid tag and a Grafana annotation at the start and end.
  2. Show on the same dashboard: k6 throughput and latency, service saturation (CPU, memory, connection pool), errors.
  3. Find the moment latency breaks down and look for the resource saturated at that instant (USE method).
  4. Open slow traces from that period (exemplars) and the service's CPU profile (Pyroscope).
import http from 'k6/http';
// Propager un en-tête de trace pour retrouver les requêtes du test dans Tempo
export default function () {
  http.get('http://api/produits', { headers: { 'X-Test-Id': __ENV.TEST_ID } });
}

📄 Observing a k6 test: Prometheus, Grafana and correlation with the system under test →

My progress

  • ⏱ Estimated time : ≈ 4 min

Sign in to track your progress and take notes. Sign in

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

Load testing with Grafana k6: why, and which types of tests

Why test performance before production, the types of tests (smoke, load, stress, spike, soak, bre...

Performance testing best practices with k6

Checklist for useful load tests: objectives, realistic scenarios, environment, thresholds, observ...

Thresholds, metrics and results of a k6 test

Read the summary of a k6 test, understand the built-in metrics (http_req_duration, http_req_faile...

Browser testing and synthetic monitoring with k6

Test a web application in a real browser with the k6 browser module, measure Core Web Vitals, and...

Website monitoring: availability, HTTPS monitoring, certificates and performance

Set up website monitoring: availability and HTTPS checks, certificate expiry, response time, Core...

Grafana Alloy: collecting and transforming telemetry

Learn how to use Grafana Alloy to collect, transform and route logs, metrics and traces. Discover...

HAProxy in Kubernetes: the high-performance Ingress Controller

Discover in depth how HAProxy integrates with Kubernetes: direct-to-pod architecture, hot update ...

Data sources in Grafana: connect and unify your data

Learn how to extend Grafana's capabilities with data sources. Discover essential plugins such as ...

k6 in continuous integration and on Kubernetes (k6-operator)

Automate performance tests: k6 in GitHub Actions and GitLab CI with blocking thresholds, distribu...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!