fix(metrics): fold provenance into account batch, pin no-store output

Provenance counters now ride the accountWith batch. They no longer use a separate droppable async write, so a request costs the same number of store round trips as before.

A golden file pins the full no-store scrape body. It was captured at the base commit, so any change to the no-store output fails the test.

A partial store failure test shows that a failed family read latches the store and skips later reads in the same scrape. The README notes the rollout-day stream label and the removal of rejection series.
This commit is contained in:
2026-11-26 02:45:51 +00:00
parent 6d55972b60
commit 50d97a3221
9 changed files with 434 additions and 27 deletions
+5 -3
View File
@@ -2941,7 +2941,6 @@ counting calls is exactly counting round trips):
| `admin.enabled: false` | 3 (2 sync — `checkAndCount`, `accountWith` — + 1 async — `recordProviderAttempt`) — `l.statsAdmin` (`adminEnabled(cfg)`, `newConfiguredLimiter`) is false, so no "always-on-with-admin" family, last-seen included, ever writes (`TestRoundTrips_SingleGroupChat_Defaults_TwoSyncOneAsync`, `stats_write_test.go`) |
| `admin.enabled: true` (`admin.stats.userModel`/`latency` on or off — **both default off, and neither changes this row**: `l.statsAdmin` is `adminEnabled(cfg)` alone, so last-seen and the rest of the always-on family are gated on `admin.enabled` by itself), cache miss or no cache, this scope's last-seen already written within `lastSeenGateThrottle` by this replica | 3 — every new counter family except last-seen rides one of the two existing sync batches above, never a new round trip; `userModel`/`latency`, when on, add entries to those SAME batches, never a new call |
| Same as above, but this scope's last-seen is DUE (its first admitted request ever, or `lastSeenGateThrottle` — 60s — has elapsed since this replica's last write for it) | 4 — adds `recordLastSeen`'s own async write (P9 fix, moved off `checkAndCount`'s own batch — see [Limits and accounting](#limits-and-accounting)). This is the common case for a request from a SCOPE'S FIRST admitted request under a fresh limiter, `admin.enabled: true` regardless of the opt-in stats (`TestRoundTrips_SingleGroupChat_AdminEnabledStatsOff_FourRoundTripsWhenLastSeenDue`, `TestRoundTrips_SingleGroupChat_AllStatsOn_NoNewSyncRoundTrips`, `stats_write_test.go`) |
| Any row above that completes an upstream call with `metrics.enabled: true` and a store | +1 async — the usage-provenance mirror (`countProvenanceShared`, `fleet_metrics.go`) that `llmgateway_usage_provenance_*` reads fleet-wide (`TestRoundTrips_SingleGroupChat_AllStatsOn_NoNewSyncRoundTrips`) |
| Cache hit (`cache.enabled: true`, `admin.enabled: true`), last-seen already throttled | 2 (`checkAndCount` + `recordCacheHit`'s async write) — `accountWith`/`recordProviderAttempt` never run at all, since the hit branch returns before either is reached |
| Cache hit, last-seen due | 3 — adds `recordLastSeen`'s own async write, same condition as the row above |
@@ -3213,7 +3212,9 @@ plugin's config.
`admin.stats.latency`, all four read the shared latency counters (UTC
day window; counters restart at the day rollover, which `rate()` treats
as a reset) and `_sum` starts at the deploy, so it can lag `_count` on
the first day; otherwise they are per process.
the first day; otherwise they are per process. On rollout day,
streaming latency recorded before the upgrade shows as `stream="false"`
until the day rolls over.
- `llmgateway_router_requests_total{router,tier,reason}` /
`llmgateway_router_escalations_total{router,from_tier,to_tier}` —
counters for [smart routers](#smart-routers). They appear after the
@@ -3248,7 +3249,8 @@ plugin's config.
one has no equivalent in the admin JSON API: nothing else tracks it.
With `redis` it is a UTC-month counter shared by all replicas
(`user` and `group` scopes only; `store_down` rejections stay local and
are not exported). Without `redis`, it does **not** reset only on
are not exported; a series disappears when its user or group is
removed from config). Without `redis`, it does **not** reset only on
process restart: a scope's own count
also resets to `0` when that user is removed via a hot-reloaded users
file, and **every** tracked scope resets together, in one bulk cliff,
+60
View File
@@ -0,0 +1,60 @@
package traefikllmgateway
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
const noStoreGoldenPath = "testdata/fleet_metrics_nostore.golden"
// noStoreGoldenScrape renders /metrics from a store-less gateway fed fixed
// observations through the in-memory recording paths, so the body is
// deterministic.
func noStoreGoldenScrape(t *testing.T) string {
t.Helper()
a := newRouterBackend(200, successRespBody)
b := newRouterBackend(200, successRespBody)
c := newRouterBackend(200, successRespBody)
defer closeBackends(a, b, c)
cfg := routerTestConfig(a, b, c, threeTiers())
cfg.Admin = &AdminConfig{Enabled: true, Stats: &AdminStatsConfig{Latency: true}}
cfg.Metrics = &MetricsConfig{Enabled: true, ModelLabel: true}
_, gw := buildRouterGateway(t, cfg)
require.Nil(t, gw.limiter.store)
gw.limiter.nowFn = func() time.Time { return time.Date(2026, 8, 20, 10, 0, 0, 0, time.UTC) }
gw.recordLatency("alpha", "a1", latencySample{duration: 300 * time.Millisecond, ttfb: 100 * time.Millisecond, hasTTFB: true})
gw.recordLatency("alpha", "a1", latencySample{duration: 1500 * time.Millisecond, ttfb: 200 * time.Millisecond, hasTTFB: true, streaming: true})
gw.recordLatency("beta", "b1", latencySample{duration: 700 * time.Second})
gw.recordPromptCache("alpha", "a1", usage{prompt: 10, cached: 8, completion: 5})
gw.recordPromptCache("beta", "b1", usage{prompt: 20, completion: 5})
gw.recordUsageProvenance("alpha", provenanceReported, 15)
gw.recordUsageProvenance("beta", provenanceEstimated, 7)
gw.recordUsageProvenance("beta", provenanceUnbilled, 0)
gw.limiter.rejections.increment("user", "alice")
gw.limiter.rejections.increment("user", "alice")
gw.routerStats.addRequest(routerRequestKey{router: routerName, tier: "t0", reason: "score"})
gw.routerStats.addRequest(routerRequestKey{router: routerName, tier: "t1", reason: "keyword"})
gw.routerStats.addEscalation(routerEscalationKey{router: routerName, from: "t0", to: "t1"})
gw.routerStats.addDecision(routerDecisionKey{router: routerName, outcome: decisionOverride})
gw.routerStats.addDecisionTier(routerDecisionTierKey{router: routerName, heuristic: "t0", model: "t1"})
return string(gw.renderMetrics())
}
// TestFleetMetricsNoStoreGolden pins the full no-store /metrics body. The
// golden was captured at the commit before the fleet-metrics change
// (UPDATE_GOLDEN=1 there), so a diff means the no-store output changed.
func TestFleetMetricsNoStoreGolden(t *testing.T) {
got := noStoreGoldenScrape(t)
if os.Getenv("UPDATE_GOLDEN") == "1" {
require.NoError(t, os.MkdirAll("testdata", 0o750))
require.NoError(t, os.WriteFile(noStoreGoldenPath, []byte(got), 0o600))
return
}
want, err := os.ReadFile(noStoreGoldenPath)
require.NoError(t, err)
require.Equal(t, string(want), got)
}
+6 -10
View File
@@ -240,18 +240,14 @@ func (g *Gateway) fleetPromptCache() (map[promptCacheKey]int64, bool) {
return out, true
}
// countProvenanceShared mirrors one provenance observation into the shared
// month counters, async and droppable.
func (g *Gateway) countProvenanceShared(provider, provenance string, tokens int64) {
if !g.fleetStore() || g.cfg == nil || !metricsEnabled(g.cfg) {
return
}
bucket := bucketFor(g.limiter.now(), windowMonth)
entries := []counterIncr{{key: provenanceKeyFor(provider, metricProvenanceReq, provenance, bucket), delta: 1, ttl: monthWindowTTL, enforceTTL: enforceTTLMonthWindow}}
// provenanceEntries returns the month-window shared counters for one
// provenance observation; they ride accountWith's own batch.
func provenanceEntries(provider, provenance string, tokens int64, monthBucket string) []counterIncr {
out := []counterIncr{{key: provenanceKeyFor(provider, metricProvenanceReq, provenance, monthBucket), delta: 1, ttl: monthWindowTTL, enforceTTL: enforceTTLMonthWindow}}
if tokens > 0 {
entries = append(entries, counterIncr{key: provenanceKeyFor(provider, metricProvenanceTok, provenance, bucket), delta: tokens, ttl: monthWindowTTL, enforceTTL: enforceTTLMonthWindow})
out = append(out, counterIncr{key: provenanceKeyFor(provider, metricProvenanceTok, provenance, monthBucket), delta: tokens, ttl: monthWindowTTL, enforceTTL: enforceTTLMonthWindow})
}
g.limiter.countAsync(entries)
return out
}
func provenanceKeyFor(provider, metric, provenance, bucket string) string {
+89
View File
@@ -274,3 +274,92 @@ func TestFleetMetricsFallsBackWhenPrerequisiteOff(t *testing.T) {
assert.Contains(t, help, "aggregate with sum()")
assert.Contains(t, fleetHelp(t, gw, "llmgateway_router_requests_total"), "aggregate with max()", "router stays store-backed")
}
// familyFailStore fails getMulti only for batches that carry a key matching
// fail; every other read and every write goes through.
type familyFailStore struct {
counterStore
fail func(key string) bool
}
func (s familyFailStore) getMulti(keys []string) ([]int64, error) {
for _, k := range keys {
if s.fail(k) {
return nil, errStoreDownStub
}
}
return s.counterStore.getMulti(keys)
}
// A failed read latches the limiter store down (storeLatched), so every read
// after it in the same scrape is skipped too. Families rendered before the
// failing one are unaffected; for the last store-backed family, only it is
// missing.
func TestFleetMetricsPartialStoreFailure(t *testing.T) {
isLatency := func(k string) bool {
for _, m := range []string{":ld", ":lt", ":lsd", ":lst"} {
if strings.Contains(k, m) {
return true
}
}
return false
}
isRejection := func(k string) bool { return strings.Contains(k, ":"+metricRej+":"+windowMonth+":") }
allFleet := []string{
"llmgateway_router_requests_total{", "llmgateway_router_escalations_total{",
"llmgateway_upstream_duration_seconds_count{", "llmgateway_upstream_ttfb_seconds_count{",
"llmgateway_prompt_cache_tokens_total{", "llmgateway_usage_provenance_requests_total{",
"llmgateway_usage_provenance_tokens_total{", "llmgateway_rate_limit_rejections_total{",
}
except := func(drop ...string) []string {
var out []string
for _, f := range allFleet {
keep := true
for _, d := range drop {
if f == d {
keep = false
}
}
if keep {
out = append(out, f)
}
}
return out
}
tests := []struct {
name string
fail func(string) bool
missing []string
present []string
}{
{"last family only", isRejection,
[]string{"llmgateway_rate_limit_rejections_total{"},
append(except("llmgateway_rate_limit_rejections_total{"), "llmgateway_requests_total{", "llmgateway_provider_healthy{")},
{"latency, then latched", isLatency,
[]string{"llmgateway_upstream_duration_seconds_count{", "llmgateway_upstream_ttfb_seconds_count{"},
[]string{"llmgateway_requests_total{", "llmgateway_provider_attempts_total{", "llmgateway_provider_healthy{"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mem := newMemoryStore()
cfg, closeAll := fleetConfig([3]int{503, 200, 200}, fleetCachedBody, 1)
defer closeAll()
gw := fleetGateway(t, cfg, mem)
require.Equal(t, 200, routerChat(t, gw, routerName, "hi", nil).Code)
require.Equal(t, 429, routerChat(t, gw, routerName, "hi", nil).Code)
base := scrape(gw)
for _, f := range allFleet {
require.True(t, strings.Contains(base, f), "baseline lacks %s", f)
}
gw.limiter.store = familyFailStore{counterStore: mem, fail: tt.fail}
out := scrape(gw)
for _, f := range tt.missing {
assert.False(t, strings.Contains(out, f), "%s must be absent", f)
}
for _, f := range tt.present {
assert.True(t, strings.Contains(out, f), "%s must be present", f)
}
})
}
}
+9
View File
@@ -1991,8 +1991,13 @@ type accountExtras struct {
// increments prov/{failoverFrom}:fover when non-empty and admin stats
// are on.
failoverFrom string
// provenance is a completed candidate's usage provenance (empty for none);
// with a store, accountWith mirrors it, and provenanceTokens, into the
// shared month counters.
provenance string
// promptCacheSaved is the micro-USD the provider prompt cache saved this call.
promptCacheSaved int64
provenanceTokens int64
// lat/hasLat carry one completed upstream watchdogBody's latency
// sample (metrics.go), when withLatencyRecorder was wired for this
// call and it actually fired — hasLat false means no sample arrived
@@ -2220,6 +2225,10 @@ func (l *limiter) accountWith(scopes []limitScope, u usage, costMicros int64, x
// each hour+day, duration always, TTFB only when the sample carries
// one (a body that never delivered a successful byte has nothing
// meaningful to report there).
if x.provenance != "" && l.store != nil {
entries = append(entries, provenanceEntries(x.provider, x.provenance, x.provenanceTokens, wb.month)...)
}
if x.hasLat && l.statsLatency {
if x.provider != "" {
entries = append(entries, latencyCounterEntries(kindProvider, x.provider, x.lat, wb, et)...)
-1
View File
@@ -1263,7 +1263,6 @@ func (s *provenanceStore) snapshot() []provenanceSnapshot {
// with metrics off calls this exactly zero times.
func (g *Gateway) recordUsageProvenance(provider, provenance string, tokens int64) {
g.provenance.record(provider, provenance, tokens)
g.countProvenanceShared(provider, provenance, tokens)
}
// writeProvenanceMetrics emits llmgateway_usage_provenance_requests_total
+16 -8
View File
@@ -786,6 +786,21 @@ func (g *Gateway) runMeteredCall(sw *statusTrackingWriter, r *http.Request, scop
extras.lat = latSample
extras.hasLat = true
}
// Provenance is derived here, before accounting, so the shared-store
// mirror rides accountWith's own batch; the in-memory record below
// stays after it.
var provenance string
if callErr == nil && metricsEnabled(g.cfg) {
provenance = provenanceReported
switch {
case result.estimated:
provenance = provenanceEstimated
case streaming && result.total() == 0:
provenance = provenanceUnbilled
}
extras.provenance = provenance
extras.provenanceTokens = result.total()
}
extras.promptCacheSaved = unifiedPromptCacheSaved(cand.canonical, cand.upstreamModel, result, g.cfg.Pricing, g.cfg.ModelMeta)
g.recordPromptCache(providerName, cand.upstreamModel, result)
g.limiter.accountWith(acctScopes, result, unifiedCostMicros(cand.canonical, cand.upstreamModel, result, g.cfg.Pricing, g.cfg.ModelMeta, g.pricingWarn), extras)
@@ -817,14 +832,7 @@ func (g *Gateway) runMeteredCall(sw *statusTrackingWriter, r *http.Request, scop
// extra here. Observation only: nothing recorded here feeds back
// into result or the account call above, both of which already
// ran — see g.recordUsageProvenance's own doc comment (metrics.go).
if callErr == nil && metricsEnabled(g.cfg) {
provenance := provenanceReported
switch {
case result.estimated:
provenance = provenanceEstimated
case streaming && result.total() == 0:
provenance = provenanceUnbilled
}
if provenance != "" {
g.recordUsageProvenance(providerName, provenance, result.total())
}
+3 -5
View File
@@ -158,9 +158,7 @@ func TestRoundTrips_SingleGroupChat_Defaults_TwoSyncOneAsync(t *testing.T) {
// this is a SEPARATE async call, not a batch this one rides. 2 sync + 2
// async = 4 total, once per admitted request from a scope l.lastSeen.due
// has not already throttled within lastSeenGateThrottle (60s) — a fresh
// limiter's first request for a scope, as this test drives. With metrics
// on and a store, the usage-provenance mirror (countProvenanceShared) adds a
// fifth, async round trip.
// limiter's first request for a scope, as this test drives.
func TestRoundTrips_SingleGroupChat_AllStatsOn_NoNewSyncRoundTrips(t *testing.T) {
srv := roundTripTestUpstream(t)
gw, counting := buildRoundTripTestGateway(t, srv, func(cfg *Config) {
@@ -176,8 +174,8 @@ func TestRoundTrips_SingleGroupChat_AllStatsOn_NoNewSyncRoundTrips(t *testing.T)
got := counting.total()
t.Logf("AFTER (admin.stats.userModel=true, admin.stats.latency=true, metrics on, no cache): %d counterStore round trips for the SAME single-group chat request", got)
if got != 5 {
t.Errorf("round trips with all stats on = %d, want 5 (2 sync + 3 async: checkAndCount, accountWith, recordProviderAttempt, recordLastSeen, provenance) — every new counter family rides an EXISTING sync batch except last-seen and, with metrics on, provenance, which are their own async writes by design", got)
if got != 4 {
t.Errorf("round trips with all stats on = %d, want 4 (2 sync + 2 async: checkAndCount, accountWith, recordProviderAttempt, recordLastSeen) — every new counter family rides an EXISTING sync batch except last-seen, which is its own async write by design (P9 fix)", got)
}
}
+246
View File
@@ -0,0 +1,246 @@
# HELP llmgateway_requests_total Total requests admitted for accounting today (UTC calendar day; resets at UTC midnight), by scope. AGGREGATION ACROSS REPLICAS: with Redis configured, this value is the gateway-wide total read from shared limit state and is IDENTICAL on every replica's own /metrics response — aggregate with max(), never sum(), or a multi-replica deployment overcounts by the replica count. Without Redis (the in-memory fallback), this SAME family becomes genuinely per-process instead, and sum() becomes the correct aggregation. Know which one you are running.
# TYPE llmgateway_requests_total counter
llmgateway_requests_total{scope_kind="user",scope_id="alice"} 0
llmgateway_requests_total{scope_kind="group",scope_id="default"} 0
llmgateway_requests_total{scope_kind="total",scope_id="all"} 0
# HELP llmgateway_tokens_total Total tokens accounted today (UTC calendar day; resets at UTC midnight), by scope and direction. AGGREGATION ACROSS REPLICAS: with Redis configured, this value is the gateway-wide total read from shared limit state and is IDENTICAL on every replica's own /metrics response — aggregate with max(), never sum(), or a multi-replica deployment overcounts by the replica count. Without Redis (the in-memory fallback), this SAME family becomes genuinely per-process instead, and sum() becomes the correct aggregation. Know which one you are running.
# TYPE llmgateway_tokens_total counter
llmgateway_tokens_total{scope_kind="user",scope_id="alice",direction="prompt"} 0
llmgateway_tokens_total{scope_kind="user",scope_id="alice",direction="completion"} 0
llmgateway_tokens_total{scope_kind="group",scope_id="default",direction="prompt"} 0
llmgateway_tokens_total{scope_kind="group",scope_id="default",direction="completion"} 0
llmgateway_tokens_total{scope_kind="total",scope_id="all",direction="prompt"} 0
llmgateway_tokens_total{scope_kind="total",scope_id="all",direction="completion"} 0
# HELP llmgateway_cost_micro_usd_total Total cost accounted today (UTC calendar day; resets at UTC midnight), in micro-USD (1000000 = $1), by scope. AGGREGATION ACROSS REPLICAS: with Redis configured, this value is the gateway-wide total read from shared limit state and is IDENTICAL on every replica's own /metrics response — aggregate with max(), never sum(), or a multi-replica deployment overcounts by the replica count. Without Redis (the in-memory fallback), this SAME family becomes genuinely per-process instead, and sum() becomes the correct aggregation. Know which one you are running.
# TYPE llmgateway_cost_micro_usd_total counter
llmgateway_cost_micro_usd_total{scope_kind="user",scope_id="alice"} 0
llmgateway_cost_micro_usd_total{scope_kind="group",scope_id="default"} 0
llmgateway_cost_micro_usd_total{scope_kind="total",scope_id="all"} 0
# HELP llmgateway_budget_consumed_ratio Fraction of a configured limit already consumed in its own window; 1.0 means fully consumed, above 1.0 means the limit has been breached. Emitted only for a scope with that particular limit configured. AGGREGATION ACROSS REPLICAS: with Redis configured, this value is the gateway-wide total read from shared limit state and is IDENTICAL on every replica's own /metrics response — aggregate with max(), never sum(), or a multi-replica deployment overcounts by the replica count. Without Redis (the in-memory fallback), this SAME family becomes genuinely per-process instead, and sum() becomes the correct aggregation. Know which one you are running.
# TYPE llmgateway_budget_consumed_ratio gauge
# HELP llmgateway_provider_attempts_total Total upstream attempts today (UTC calendar day; resets at UTC midnight), by provider. AGGREGATION ACROSS REPLICAS: with Redis configured, this value is the gateway-wide total read from shared limit state and is IDENTICAL on every replica's own /metrics response — aggregate with max(), never sum(), or a multi-replica deployment overcounts by the replica count. Without Redis (the in-memory fallback), this SAME family becomes genuinely per-process instead, and sum() becomes the correct aggregation. Know which one you are running.
# TYPE llmgateway_provider_attempts_total counter
llmgateway_provider_attempts_total{provider="alpha"} 0
llmgateway_provider_attempts_total{provider="beta"} 0
llmgateway_provider_attempts_total{provider="gamma"} 0
# HELP llmgateway_provider_failures_total Total upstream attempts today classified as a provider fault (transport error, 429, or 5xx — the same classification recordProviderAttempt/isTransient apply), by provider. AGGREGATION ACROSS REPLICAS: with Redis configured, this value is the gateway-wide total read from shared limit state and is IDENTICAL on every replica's own /metrics response — aggregate with max(), never sum(), or a multi-replica deployment overcounts by the replica count. Without Redis (the in-memory fallback), this SAME family becomes genuinely per-process instead, and sum() becomes the correct aggregation. Know which one you are running.
# TYPE llmgateway_provider_failures_total counter
llmgateway_provider_failures_total{provider="alpha"} 0
llmgateway_provider_failures_total{provider="beta"} 0
llmgateway_provider_failures_total{provider="gamma"} 0
# HELP llmgateway_provider_healthy 1 when the provider's discovery circuit breaker is not open (closed or half-open), 0 when open (discoveryHealthy, registry.go). AGGREGATION ACROSS REPLICAS: each replica runs its own discovery circuit breaker in-process, never shared via Redis, so this can legitimately differ per replica. Read it per-instance where possible; if you must aggregate, use min() to surface "at least one replica sees this provider as unhealthy" — sum() is meaningless for a 0/1 gauge.
# TYPE llmgateway_provider_healthy gauge
llmgateway_provider_healthy{provider="alpha"} 1
llmgateway_provider_healthy{provider="beta"} 1
llmgateway_provider_healthy{provider="gamma"} 1
# HELP llmgateway_provider_model_attempts_total Total upstream attempts today (UTC calendar day; resets at UTC midnight), by provider and model. Opt-in via metrics.modelLabel — see MetricsConfig's own doc comment for the cardinality trade-off. AGGREGATION ACROSS REPLICAS: with Redis configured, this value is the gateway-wide total read from shared limit state and is IDENTICAL on every replica's own /metrics response — aggregate with max(), never sum(), or a multi-replica deployment overcounts by the replica count. Without Redis (the in-memory fallback), this SAME family becomes genuinely per-process instead, and sum() becomes the correct aggregation. Know which one you are running.
# TYPE llmgateway_provider_model_attempts_total counter
llmgateway_provider_model_attempts_total{provider="alpha",model="a1"} 0
llmgateway_provider_model_attempts_total{provider="alpha",model="a2"} 0
llmgateway_provider_model_attempts_total{provider="beta",model="b1"} 0
llmgateway_provider_model_attempts_total{provider="gamma",model="c1"} 0
# HELP llmgateway_provider_model_failures_total Total upstream attempts today classified as a provider fault, by provider and model. Opt-in via metrics.modelLabel. AGGREGATION ACROSS REPLICAS: with Redis configured, this value is the gateway-wide total read from shared limit state and is IDENTICAL on every replica's own /metrics response — aggregate with max(), never sum(), or a multi-replica deployment overcounts by the replica count. Without Redis (the in-memory fallback), this SAME family becomes genuinely per-process instead, and sum() becomes the correct aggregation. Know which one you are running.
# TYPE llmgateway_provider_model_failures_total counter
llmgateway_provider_model_failures_total{provider="alpha",model="a1"} 0
llmgateway_provider_model_failures_total{provider="alpha",model="a2"} 0
llmgateway_provider_model_failures_total{provider="beta",model="b1"} 0
llmgateway_provider_model_failures_total{provider="gamma",model="c1"} 0
# HELP llmgateway_upstream_ttfb_seconds Time to first successful byte read from an upstream response body, in seconds, measured from just before the request was sent (watchdogBody, timeout.go). Meaningful as a distinct "how fast did the provider start responding" signal only for stream="true": a non-streaming provider buffers its whole completion before sending anything, so its own TTFB is approximately equal to its own llmgateway_upstream_duration_seconds and carries the same output-length contamination duration does — always split by the stream label before comparing across requests of different lengths, never averaged across it. AGGREGATION ACROSS REPLICAS: this histogram lives only in this process's memory, never in Redis, regardless of Config.Redis — each replica reports only the upstream traffic it personally handled, so aggregate with sum() (histogram_quantile over a sum()-aggregated set, for a real percentile), which is always correct for it, unlike the store-backed families above that flip between sum() and max() depending on whether Redis is configured.
# TYPE llmgateway_upstream_ttfb_seconds histogram
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="0.1"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="0.25"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="0.5"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="1"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="2"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="5"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="10"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="15"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="30"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="60"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="120"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="300"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="600"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="false",le="+Inf"} 1
llmgateway_upstream_ttfb_seconds_sum{provider="alpha",stream="false"} 0.1
llmgateway_upstream_ttfb_seconds_count{provider="alpha",stream="false"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="0.1"} 0
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="0.25"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="0.5"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="1"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="2"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="5"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="10"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="15"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="30"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="60"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="120"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="300"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="600"} 1
llmgateway_upstream_ttfb_seconds_bucket{provider="alpha",stream="true",le="+Inf"} 1
llmgateway_upstream_ttfb_seconds_sum{provider="alpha",stream="true"} 0.2
llmgateway_upstream_ttfb_seconds_count{provider="alpha",stream="true"} 1
# HELP llmgateway_upstream_duration_seconds Total upstream response body duration, in seconds, from just before the request was sent to the last successful read or Close (watchdogBody, timeout.go) — covers the whole body, not just headers. Roughly TTFB + output_tokens/tokens_per_sec: a long generation legitimately takes longer than a short one on an equally healthy provider, so a raw average across requests of very different output length is not by itself a "provider degraded" signal — llmgateway_tokens_total's completion direction (this file) gives the token side of that ratio for the non-streaming population, where duration approximates total generation time. AGGREGATION ACROSS REPLICAS: this histogram lives only in this process's memory, never in Redis, regardless of Config.Redis — each replica reports only the upstream traffic it personally handled, so aggregate with sum() (histogram_quantile over a sum()-aggregated set, for a real percentile), which is always correct for it, unlike the store-backed families above that flip between sum() and max() depending on whether Redis is configured.
# TYPE llmgateway_upstream_duration_seconds histogram
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="0.1"} 0
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="0.25"} 0
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="0.5"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="1"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="2"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="5"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="10"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="15"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="30"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="60"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="120"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="300"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="600"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="false",le="+Inf"} 1
llmgateway_upstream_duration_seconds_sum{provider="alpha",stream="false"} 0.3
llmgateway_upstream_duration_seconds_count{provider="alpha",stream="false"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="0.1"} 0
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="0.25"} 0
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="0.5"} 0
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="1"} 0
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="2"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="5"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="10"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="15"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="30"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="60"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="120"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="300"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="600"} 1
llmgateway_upstream_duration_seconds_bucket{provider="alpha",stream="true",le="+Inf"} 1
llmgateway_upstream_duration_seconds_sum{provider="alpha",stream="true"} 1.5
llmgateway_upstream_duration_seconds_count{provider="alpha",stream="true"} 1
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="0.1"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="0.25"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="0.5"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="1"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="2"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="5"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="10"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="15"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="30"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="60"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="120"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="300"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="600"} 0
llmgateway_upstream_duration_seconds_bucket{provider="beta",stream="false",le="+Inf"} 1
llmgateway_upstream_duration_seconds_sum{provider="beta",stream="false"} 700
llmgateway_upstream_duration_seconds_count{provider="beta",stream="false"} 1
# HELP llmgateway_upstream_model_ttfb_seconds Time to first successful byte read from an upstream response body, in seconds, by provider, stream, and model. Opt-in via metrics.modelLabel — see MetricsConfig's own doc comment for the cardinality trade-off. A separate metric name from llmgateway_upstream_ttfb_seconds (M4 fix), not the same series with an extra label, so summing one family never double-counts the other's requests. AGGREGATION ACROSS REPLICAS: this histogram lives only in this process's memory, never in Redis, regardless of Config.Redis — each replica reports only the upstream traffic it personally handled, so aggregate with sum() (histogram_quantile over a sum()-aggregated set, for a real percentile), which is always correct for it, unlike the store-backed families above that flip between sum() and max() depending on whether Redis is configured.
# TYPE llmgateway_upstream_model_ttfb_seconds histogram
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="0.1"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="0.25"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="0.5"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="1"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="2"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="5"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="10"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="15"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="30"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="60"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="120"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="300"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="600"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="false",model="a1",le="+Inf"} 1
llmgateway_upstream_model_ttfb_seconds_sum{provider="alpha",stream="false",model="a1"} 0.1
llmgateway_upstream_model_ttfb_seconds_count{provider="alpha",stream="false",model="a1"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="0.1"} 0
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="0.25"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="0.5"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="1"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="2"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="5"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="10"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="15"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="30"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="60"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="120"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="300"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="600"} 1
llmgateway_upstream_model_ttfb_seconds_bucket{provider="alpha",stream="true",model="a1",le="+Inf"} 1
llmgateway_upstream_model_ttfb_seconds_sum{provider="alpha",stream="true",model="a1"} 0.2
llmgateway_upstream_model_ttfb_seconds_count{provider="alpha",stream="true",model="a1"} 1
# HELP llmgateway_upstream_model_duration_seconds Total upstream response body duration, in seconds, by provider, stream, and model. Opt-in via metrics.modelLabel. A separate metric name from llmgateway_upstream_duration_seconds (M4 fix), not the same series with an extra label, so summing one family never double-counts the other's requests. AGGREGATION ACROSS REPLICAS: this histogram lives only in this process's memory, never in Redis, regardless of Config.Redis — each replica reports only the upstream traffic it personally handled, so aggregate with sum() (histogram_quantile over a sum()-aggregated set, for a real percentile), which is always correct for it, unlike the store-backed families above that flip between sum() and max() depending on whether Redis is configured.
# TYPE llmgateway_upstream_model_duration_seconds histogram
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="0.1"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="0.25"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="0.5"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="1"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="2"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="5"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="10"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="15"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="30"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="60"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="120"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="300"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="600"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="false",model="a1",le="+Inf"} 1
llmgateway_upstream_model_duration_seconds_sum{provider="alpha",stream="false",model="a1"} 0.3
llmgateway_upstream_model_duration_seconds_count{provider="alpha",stream="false",model="a1"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="0.1"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="0.25"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="0.5"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="1"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="2"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="5"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="10"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="15"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="30"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="60"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="120"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="300"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="600"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="alpha",stream="true",model="a1",le="+Inf"} 1
llmgateway_upstream_model_duration_seconds_sum{provider="alpha",stream="true",model="a1"} 1.5
llmgateway_upstream_model_duration_seconds_count{provider="alpha",stream="true",model="a1"} 1
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="0.1"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="0.25"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="0.5"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="1"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="2"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="5"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="10"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="15"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="30"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="60"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="120"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="300"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="600"} 0
llmgateway_upstream_model_duration_seconds_bucket{provider="beta",stream="false",model="b1",le="+Inf"} 1
llmgateway_upstream_model_duration_seconds_sum{provider="beta",stream="false",model="b1"} 700
llmgateway_upstream_model_duration_seconds_count{provider="beta",stream="false",model="b1"} 1
# HELP llmgateway_usage_provenance_requests_total Total accounted candidate outcomes (a successful upstream response, callErr == nil, that reached usage accounting in runUnified, routes_unified.go), by provider and provenance. provenance is "reported" (the provider returned real usage), "estimated" (a non-streaming response carried none, so prompt was substituted with ceil(len(body)/4) and completion billed as zero — usage.estimated, limits.go), or "unbilled" (a streaming response carried none, so the request is counted but zero tokens are billed). This family only reports how an already-billed number was arrived at; it never changes what gets billed. AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above.
# TYPE llmgateway_usage_provenance_requests_total counter
llmgateway_usage_provenance_requests_total{provider="alpha",provenance="reported"} 1
llmgateway_usage_provenance_requests_total{provider="beta",provenance="estimated"} 1
llmgateway_usage_provenance_requests_total{provider="beta",provenance="unbilled"} 1
# HELP llmgateway_usage_provenance_tokens_total Total tokens billed under each provenance (the SAME result.total() runUnified already passed to accounting, routes_unified.go — never a second, independent count), by provider and provenance. sum(...{provenance="reported"}) / sum(...) across every provenance is the fraction of billed tokens that came from real provider-reported usage. AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above.
# TYPE llmgateway_usage_provenance_tokens_total counter
llmgateway_usage_provenance_tokens_total{provider="alpha",provenance="reported"} 15
llmgateway_usage_provenance_tokens_total{provider="beta",provenance="estimated"} 7
llmgateway_usage_provenance_tokens_total{provider="beta",provenance="unbilled"} 0
# HELP llmgateway_router_requests_total Smart router requests by router, first attempted tier and routing reason (score, keyword, floor, model, default, or skipped when lower tiers had no usable target). AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above.
# TYPE llmgateway_router_requests_total counter
llmgateway_router_requests_total{router="auto",tier="t0",reason="score"} 1
llmgateway_router_requests_total{router="auto",tier="t1",reason="keyword"} 1
# HELP llmgateway_router_decision_total Smart router decision-model calls by router and outcome (agree, override, lowconf, timeout, error, breaker, cache). AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above.
# TYPE llmgateway_router_decision_total counter
llmgateway_router_decision_total{router="auto",outcome="override"} 1
# HELP llmgateway_router_decision_tiers_total Smart router answers from the decision model or its cache by router, heuristic tier and model-ranked tier. AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above.
# TYPE llmgateway_router_decision_tiers_total counter
llmgateway_router_decision_tiers_total{router="auto",heuristic="t0",model="t1"} 1
# HELP llmgateway_router_escalations_total Smart router attempts that moved to a higher tier after a failure, by router, from_tier and to_tier. Same-tier failover is not counted. AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above.
# TYPE llmgateway_router_escalations_total counter
llmgateway_router_escalations_total{router="auto",from_tier="t0",to_tier="t1"} 1
# HELP llmgateway_prompt_cache_tokens_total Prompt tokens by provider, model and kind (read: served from the provider prompt cache, write: written to it, uncached: neither). AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above.
# TYPE llmgateway_prompt_cache_tokens_total counter
llmgateway_prompt_cache_tokens_total{provider="alpha",model="a1",kind="read"} 8
llmgateway_prompt_cache_tokens_total{provider="alpha",model="a1",kind="uncached"} 2
llmgateway_prompt_cache_tokens_total{provider="beta",model="b1",kind="uncached"} 20
# HELP llmgateway_rate_limit_rejections_total Total requests refused by a rate or budget limit since process start, by scope. Unlike the request/token/cost counters above, this is a process-lifetime counter, not UTC-day-windowed, but it does NOT reset only on restart: a scope's own count resets to 0 when that user is removed via a hot-reloaded users file, and every tracked scope resets together, in one bulk cliff (not a graceful per-scope decay), the instant more than 2000 distinct scopes have ever been seen — a value that drops is one of these events, not a scrape anomaly. AGGREGATION ACROSS REPLICAS: this counter lives only in this process's memory, never in Redis, regardless of Config.Redis — aggregate with sum(), which is always correct for it, unlike the store-backed families above.
# TYPE llmgateway_rate_limit_rejections_total counter
llmgateway_rate_limit_rejections_total{scope_kind="user",scope_id="alice"} 2