1. Why export? #
The summary is not enough.
Seeing over time #
Available in: ✓ OSS ✓ Enterprise ✓ Cloud
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-receiverK6_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 metric | Origin |
|---|---|
k6_http_reqs_total | http_reqs counter |
k6_http_req_duration_p95 | Statistic requested in TREND_STATS |
k6_http_req_failed_rate | Failure rate |
k6_vus | Virtual 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 #
- Mark the test:
testidtag and a Grafana annotation at the start and end. - Show on the same dashboard: k6 throughput and latency, service saturation (CPU, memory, connection pool), errors.
- Find the moment latency breaks down and look for the resource saturated at that instant (USE method).
- 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 } });
}My progress
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.
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...