# 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" ]
