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:| Option | Environment Variable | Description | Default |
|---|---|---|---|
saveInterval | K6_CSV_SAVE_INTERVAL | How often to flush data | 1s |
timeFormat | K6_CSV_TIME_FORMAT | Timestamp format: unix, unix_nano, unix_micro, unix_milli, rfc3339, rfc3339_nano | unix |
fileName | K6_CSV_FILENAME | Output file path | file.csv |
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:
InfluxDB v2 Configuration Options:
| Environment Variable | Default | Description |
|---|---|---|
K6_INFLUXDB_ORGANIZATION | - | InfluxDB organization name |
K6_INFLUXDB_BUCKET | - | Bucket name for k6 metrics |
K6_INFLUXDB_TOKEN | - | API token for authentication |
K6_INFLUXDB_ADDR | http://localhost:8086 | InfluxDB server address |
K6_INFLUXDB_PUSH_INTERVAL | 1s | Metric flush frequency |
K6_INFLUXDB_CONCURRENT_WRITES | 4 | Number of concurrent write requests |
K6_INFLUXDB_TAGS_AS_FIELDS | vu:int,iter:int,url | Comma-separated tags to store as fields |
K6_INFLUXDB_INSECURE | false | Skip HTTPS certificate verification |
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