You can output granular data points in JSON format. To do so, use k6 run with the --out flag. Pass the path for your JSON file as the flag argument:
Or if you want to get the result gzipped, like this:
To inspect the output in real time, you can use a command like tail -f on the file you save:
JSON format
The JSON file will have lines like these:
Each line either has information about a metric, or logs a data point (sample) for a metric. Lines consist of three items:
- type - can have the values Metric or Point where Metric means the line is declaring a metric, and Point is an actual data point (sample) for a metric.
- data - is a dictionary that contains lots of stuff, varying depending on the "type" above.
- metric - the name of the metric.
Metric
This line has metadata about a metric. Here, "data" contains the following:
- "type" - the metric type ("gauge", "rate", "counter" or "trend")
- "contains" - information on the type of data collected (can e.g. be "time" for timing metrics)
- "tainted" - has this metric caused a threshold to fail?
- "threshold" - are there any thresholds attached to this metric?
- "submetrics" - any derived metrics created as a result of adding a threshold using tags.
Point
This line has actual data samples. Here, "data" contains these fields:
- "time" - timestamp when the sample was collected
- "value" - the actual data sample; time values are in milliseconds
- "tags" - dictionary with tagname-tagvalue pairs that can be used when filtering results data
Processing JSON output
You can use jq to process the k6 JSON output.
You can quickly create filters to return a particular metric of the JSON file:
And calculate an aggregated value of any metric:
For more advanced cases, check out the jq Manual
Summary export
If you want to see only the aggregated data, you can export the end-of-test summary to a JSON file. For more details, refer to the handleSummary() topic in the end-of-test summary docs.