Real-Time Result Streaming
Besides the end-of-test summary, k6 can stream metrics as granular data points in real time. This enables live monitoring, long-term storage, and integration with external observability platforms.Overview
Real-time streaming allows you to:- Monitor test progress as it runs
- Store metrics for historical analysis
- Integrate with existing monitoring systems
- Build custom dashboards and alerts
- Process metrics with your own tools
--out flag.
Output to Files
k6 supports streaming metrics to local files in two formats:CSV
Simple, human-readable format
JSON
Structured format with full metadata
CSV Output
CSV output provides a simple, tabular format with one metric value per line:
Monitor in real time:
JSON Output
JSON output provides structured data with complete metric metadata:For the aggregated end-of-test summary as JSON, use the
handleSummary() function instead of --out json.Output to Services
k6 can stream metrics to various external services and databases:- Grafana Cloud
- InfluxDB
- Prometheus
- Other Services
Stream directly to Grafana Cloud k6 for managed storage and visualization:Requires a Grafana Cloud k6 account.
InfluxDB Example
Here’s a complete workflow for streaming to InfluxDB v2:1
Install xk6
2
Build k6 with extension
3
Run test
4
Visualize in Grafana
Connect Grafana to your InfluxDB instance and use pre-built dashboards or create custom ones.
Multiple Outputs
You can stream to multiple destinations simultaneously:- Archiving raw data while monitoring in real time
- Sending to multiple monitoring systems
- Creating backups of test results
Docker Example
Stream results when running k6 in Docker:Performance Considerations
Streaming real-time metrics can impact test performance, especially at high load. Consider:
- Increasing
saveIntervalorpushIntervalfor high-throughput tests - Using efficient backends (InfluxDB, Prometheus) instead of JSON files
- Running k6 and the monitoring backend on separate machines
- Monitoring the resource usage of both k6 and the output backend
Building Custom Output Extensions
You can create your own output format using xk6:Next Steps
Grafana Dashboards
Visualize real-time metrics with Grafana
Web Dashboard
Use the built-in web dashboard for live monitoring
Metrics Reference
Learn about all available k6 metrics
Output Extensions
Build custom output formats