Metrics
Metrics measure how a system performs under test conditions. By default, k6 automatically collects built-in metrics. Besides built-ins, you can also make custom metrics.
Metrics fall into four broad types:
- Counters sum values.
- Gauges track the smallest, largest, and latest values.
- Rates track how frequently a non-zero value occurs.
- Trends calculates statistics for multiple values (like mean, mode or percentile).
To make a test fail a certain criteria, you can write a Threshold based on the metric criteria (the specifics of the expression depend on the metric type). To filter metrics, you can use Tags and groups. You can also export metrics in various summary and granular formats, as documented in Results output.
What metrics to look at?
Each metric provides a different perspective on performance. So the best metric for your analysis depends on your goals.
However, if you’re unsure about the metrics to focus on, you can start with the metrics that measure the requests, errors, and duration (the criteria of the RED method).
http_reqs
, to measure requestshttp_req_failed
, to measure error ratehttp_req_duration
, to measure duration
Note
In other terminology, these metrics measure traffic (in requests), availability (in error rate), and latency (in request duration). SREs might recognize these metrics as three of the four Golden Signals.
Example output
An aggregated summary of all built-in and custom metrics outputs to stdout
when you run a test:
import http from 'k6/http';
export default function () {
http.get('https://test-api.k6.io/');
}
The preceding script outputs something like this:
In that output, all the metrics that start with http
, iteration
, and vu
are built-in metrics, which get written to stdout at the end of a test.
For details of all metrics, refer to the Metrics reference.
Metric name restrictions
Metric names must comply with OpenTelemetry and Prometheus limitations. The character limit is the same limit k6 had before restricting the character set down.
That means metrics names must:
- Include up to 128 symbols (ASCII letters, numbers, or underscores).
- Start with a letter or an underscore.