Metric Types
k6 supports four metric types, defined inmetrics/metric_type.go:
Counter
A metric that sums all added values. Frommetrics/metric_type.go:
count, rate
Gauge
A metric that stores the latest value. Frommetrics/metric_type.go:
value
Trend
A metric that tracks all values and calculates statistics. Frommetrics/metric_type.go:
avg, min, max, med, p(N) (percentiles)
Rate
A metric that tracks the percentage of non-zero values. Frommetrics/metric_type.go:
rate
Built-in Metrics
k6 automatically collects comprehensive metrics defined inmetrics/builtin.go:
HTTP Metrics
Frommetrics/builtin.go, HTTP-related metrics:
http_reqs
Type: CounterDescription: Total number of HTTP requests
http_req_failed
Type: RateDescription: Rate of failed requests (status >= 400 or network error)
http_req_duration
Type: Trend (Time)Description: Total request time (sending + waiting + receiving)
http_req_blocked
Type: Trend (Time)Description: Time blocked before initiating request (waiting for free TCP connection)
http_req_connecting
Type: Trend (Time)Description: Time spent establishing TCP connection
http_req_tls_handshaking
Type: Trend (Time)Description: Time spent in TLS handshake
http_req_sending
Type: Trend (Time)Description: Time spent sending request data
http_req_waiting
Type: Trend (Time)Description: Time spent waiting for response (TTFB - Time To First Byte)
http_req_receiving
Type: Trend (Time)Description: Time spent receiving response data
VU and Iteration Metrics
vus
Type: GaugeDescription: Current number of active virtual users
vus_max
Type: GaugeDescription: Maximum number of VUs initialized
iterations
Type: CounterDescription: Total number of completed iterations
iteration_duration
Type: Trend (Time)Description: Time to complete one full iteration
dropped_iterations
Type: CounterDescription: Iterations that couldn’t start due to time constraints
Check Metrics
checks
Type: RateDescription: Success rate of checks
Group Metrics
group_duration
Type: Trend (Time)Description: Time spent inside a group
WebSocket Metrics
Frommetrics/builtin.go, WebSocket-specific metrics:
ws_sessions(Counter) - Total WebSocket sessionsws_msgs_sent(Counter) - Messages sentws_msgs_received(Counter) - Messages receivedws_ping(Trend, Time) - Ping durationws_session_duration(Trend, Time) - Session durationws_connecting(Trend, Time) - Connection time
gRPC Metrics
grpc_req_duration
Type: Trend (Time)Description: gRPC request duration
Network Metrics
data_sent
Type: Counter (Data)Description: Amount of data sent (bytes)
data_received
Type: Counter (Data)Description: Amount of data received (bytes)
Custom Metrics
Create custom metrics to track application-specific data. Fromexamples/custom_metrics.js:
Metric Tags
Frommetrics/tags.go, metrics can be filtered using tags:
System Tags
Automatic tags frommetrics/system_tag.go:
method- HTTP methodstatus- HTTP status codeurl- Request URLname- Request namegroup- Group namecheck- Check namescenario- Scenario nameservice- Service name (for gRPC)
Custom Tags
Add custom tags to requests:Global Tags
Apply tags to all metrics:Metric Output
End-of-Test Summary
k6 displays metric statistics at test completion:Metric Value Types
Frommetrics/value_type.go, metrics can represent:
- Default - Generic numeric values
- Time - Duration values (milliseconds)
- Data - Data size values (bytes)
Advanced Metric Patterns
Tracking Business Metrics
Tracking Error Types
Conditional Metrics
Best Practices
1
Use Built-in Metrics First
Built-in metrics cover most use cases. Only add custom metrics when necessary.
2
Choose the Right Metric Type
Use Counter for totals, Gauge for latest values, Trend for statistics, and Rate for success rates.
3
Add Meaningful Tags
Tag metrics to enable filtering and detailed analysis.
4
Combine Metrics with Thresholds
Use metrics with thresholds to define pass/fail criteria.