Custom metrics
Scripting & metricsTrack what matters to you — revenue booked, cache-hit rate, a bespoke latency, queue depth — by declaring metrics and emitting to them from JS, then gating on them with thresholds like any built-in.
Browse all 52 demos 12 categories
No demos match.
$ loadr run examples/39-custom-metrics.yaml
# User-defined metrics — Artillery's `track-custom-metrics`.
#
# Declare your own metrics under `metrics:` and emit to them from JS:
# counter -> session.counterAdd(name, n) (monotonic totals, e.g. £ booked)
# rate -> session.rateAdd(name, bool) (proportion true, e.g. cache hits)
# trend -> session.trendAdd(name, value) (distribution, e.g. a custom latency)
# gauge -> session.gaugeSet(name, value) (last value, e.g. queue depth)
# Tag requests by endpoint so the built-in HTTP metrics break down per route too.
#
# loadr run examples/39-custom-metrics.yaml
name: custom-metrics
description: custom counter/rate/trend/gauge metrics + per-endpoint breakdown
defaults:
http:
base_url: https://api.example.com
js:
file: scripts/custom-metrics.js
metrics:
revenue_usd: { kind: counter }
cache_hit: { kind: rate }
checkout_latency: { kind: trend, time: true }
inflight_orders: { kind: gauge }
scenarios:
shop:
executor: constant-vus
vus: 10
duration: 1m
exec: shop
thresholds:
checks: [ "rate>0.98" ]
cache_hit: [ "rate>0.80" ]
checkout_latency: [ "p(95)<800" ]View raw: examples/39-custom-metrics.yaml
Related files: scripts/custom-metrics.js
What it shows
- ▸counter / rate / trend / gauge kinds
- ▸
session.counterAdd/rateAdd/trendAdd/gaugeSet - ▸Threshold on custom metrics
Key metrics: revenue_usd · cache_hit · checkout_latency.