Documentation
¶
Overview ¶
Package agentmetrics exposes a Prometheus / OpenMetrics HTTP handler for a gopheragent BudgetTracker. It lives outside pkg/agent so applications that embed the agent loop in a CLI or batch tool do not transitively import net/http.
Usage:
bt := agent.NewBudgetTracker(100_000)
loop.OnEvent(bt.Handler())
http.Handle("/metrics", agentmetrics.Handler(bt))
The output is valid OpenMetrics 1.0 (and therefore Prometheus text format), so any Prometheus-compatible scraper can ingest it directly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(bt *agent.BudgetTracker) http.Handler
Handler returns an http.Handler that renders the tracker's per-session token usage in OpenMetrics text format.
Metrics emitted:
- gopheragent_session_prompt_tokens_total{session_key} (counter)
- gopheragent_session_completion_tokens_total{session_key} (counter)
- gopheragent_session_tokens_total{session_key} (counter, sum of the two above)
- gopheragent_session_budget_tokens{session_key} (gauge, the configured ceiling)
- gopheragent_session_budget_remaining_tokens{session_key} (gauge, budget - total; omitted when Budget == 0)
Cardinality note: every distinct session_key produces its own series. If the tracker is used with short-lived per-request keys, the caller should reset or evict entries when a session ends so the exporter does not carry a growing label set.
Types ¶
This section is empty.