mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(metrics): render fleet-wide families from the shared store
The /metrics route runs in its own instance. That instance handles no chat traffic, so its in-memory families stayed empty. With a limiter store, /metrics now reads the router, decision, latency, prompt-cache, provenance and rejection families from shared counters. Their HELP text uses the store-backed aggregation note. Without a store, or without the stats flag a family needs, the in-memory rendering is unchanged. The latency counters gain day-window sums in milliseconds and streaming-only bucket counters. The histograms can then emit a real _sum and keep the stream label. Provenance writes use countAsync. The rejection month counter rides the existing rejection batch. A store read failure skips the affected families.
This commit is contained in:
+10
-1
@@ -79,6 +79,15 @@ func unifiedPromptCacheSaved(canonical, bare string, u usage, overrides map[stri
|
||||
|
||||
func (g *Gateway) writePromptCacheMetrics(m *metricWriter) {
|
||||
snap := g.promptCacheStats.snapshot()
|
||||
note := aggregationNotePerProcess
|
||||
if g.fleetStore() {
|
||||
fleet, ok := g.fleetPromptCache()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
snap = fleet
|
||||
note = aggregationNoteStoreBacked
|
||||
}
|
||||
if len(snap) == 0 {
|
||||
return
|
||||
}
|
||||
@@ -97,7 +106,7 @@ func (g *Gateway) writePromptCacheMetrics(m *metricWriter) {
|
||||
return x.kind < y.kind
|
||||
})
|
||||
m.family("llmgateway_prompt_cache_tokens_total", "counter",
|
||||
"Prompt tokens by provider, model and kind (read: served from the provider prompt cache, write: written to it, uncached: neither)."+aggregationNotePerProcess)
|
||||
"Prompt tokens by provider, model and kind (read: served from the provider prompt cache, write: written to it, uncached: neither)."+note)
|
||||
for _, k := range keys {
|
||||
m.sampleInt("llmgateway_prompt_cache_tokens_total",
|
||||
[]metricLabel{{"provider", k.provider}, {"model", k.model}, {"kind", k.kind}}, snap[k])
|
||||
|
||||
Reference in New Issue
Block a user