Skip to main content
The k6/metrics module provides classes for creating custom metrics.

Metric Types

Counter

A metric that cumulatively sums added values.
string
Metric name (must be unique)
boolean
Whether the metric represents time values

add(value, [tags])

Adds a value to the counter.
number
Value to add
object
Custom tags for this data point

Gauge

A metric that stores the latest value added to it.
string
Metric name (must be unique)
boolean
Whether the metric represents time values

add(value, [tags])

Sets the gauge to the specified value.

Rate

A metric that tracks the percentage of added values that are non-zero.
string
Metric name (must be unique)
boolean
Whether the metric represents time values

add(value, [tags])

Adds a boolean or numeric value to the rate.

Trend

A metric that calculates statistics (min, max, avg, percentiles) on added values.
string
Metric name (must be unique)
boolean
Whether the metric represents time values (enables time-based formatting)

add(value, [tags])

Adds a value to the trend.

Complete Example

Usage Notes

Custom metrics must be declared in the init context (outside the default function). Adding values to metrics can only be done in the VU context.

Metric Tags

You can attach custom tags to individual metric data points: