Skip to main content
The k6/metrics module provides custom metric types for tracking and aggregating performance data in your tests.

Import

Metric Types

Counter

Counter is a cumulative metric that only increases. Use it to count events, errors, or accumulate values.
string
required
The name of the custom metric.
Methods:
  • add(value, [tags]) - Add a value to the counter
Threshold variables:
  • count - The total count value
  • rate - The rate of the counter
Examples: count >= 200, count < 10

Gauge

Gauge holds only the latest value added. Use it for tracking current state or the most recent measurement.
string
required
The name of the custom metric.
boolean
Indicates whether the values are time values or untyped values.
Methods:
  • add(value, [tags]) - Add a value to the gauge (only the latest value is kept)
Threshold variable:
  • value - The current gauge value
Examples: value < 200, value > 1

Rate

Rate tracks the percentage of added values that are non-zero. Use it for calculating success/failure rates.
string
required
The name of the custom metric.
Methods:
  • add(value, [tags]) - Add a boolean or numeric value (non-zero counts as true)
Threshold variable:
  • rate - The rate value between 0.00 and 1.00
Examples: rate < 0.1 (less than 10%), rate >= 0.9 (90% or more)

Trend

Trend calculates statistics on added values (min, max, average, percentiles). Use it for timing measurements and performance analysis.
string
required
The name of the custom metric.
boolean
Indicates whether the values are time values (in milliseconds) or untyped values.
Methods:
  • add(value, [tags]) - Add a value to the trend
Threshold variables:
  • avg - Average value
  • min - Minimum value (not recommended for thresholds)
  • max - Maximum value (not recommended for thresholds)
  • med - Median value
  • p(N) - Specific percentile (N between 0.0 and 100.0)
Examples:
  • p(95) < 400 - 95% of requests finish below 400ms
  • p(99) < 1000 - 99% of requests finish within 1s
  • p(50) < 200 - Half of requests finish within 200ms
  • max < 3000 - Slowest request finishes within 3s
Don’t use min and max for thresholds as they represent outliers. Use percentiles instead.