Documentation
¶
Overview ¶
Package metrics is a zero-dependency, lock-free performance counter registry embedded in the agent. It tracks turns, tokens, tool calls, cache hits, errors, and latencies using atomic counters so it's safe to read from any goroutine without blocking the hot path.
The counters are exposed via `ok doctor --metrics` and can be introspected by the agent itself at runtime (self-aware infrastructure).
Index ¶
- func CacheHit()
- func CacheHitRate() float64
- func CacheMiss()
- func Compaction()
- func ErrorNonRetry()
- func ErrorRate() float64
- func ErrorRetry()
- func HealthScore() int
- func MeanToolLatency() time.Duration
- func MeanTurnLatency() time.Duration
- func Panic()
- func Snapshot()
- func Start()
- func Tokens(prompt, output int64)
- func ToolCall()
- func ToolDenied()
- func ToolError()
- func ToolLatency(d time.Duration)
- func ToolResult()
- func Turn()
- func TurnCancelled()
- func TurnLatency(d time.Duration)
- func TurnSucceeded()
- func Uptime() time.Duration
- func WriteReport(w io.Writer)
- type Registry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheHitRate ¶
func CacheHitRate() float64
CacheHitRate returns the cache hit ratio (0..1), or 0 if no data.
func HealthScore ¶
func HealthScore() int
HealthScore returns 0-100 reflecting overall agent health.
func MeanToolLatency ¶
MeanToolLatency returns the average tool execution duration, or 0.
func MeanTurnLatency ¶
MeanTurnLatency returns the average turn duration, or 0.
func ToolLatency ¶
ToolLatency records the duration of a tool execution in microseconds.
func TurnLatency ¶
TurnLatency records the duration of a completed turn in microseconds.
func WriteReport ¶
WriteReport writes a human-readable metrics report to w.
Types ¶
type Registry ¶
type Registry struct {
Turns atomic.Int64 // total turns submitted
TurnsSucceeded atomic.Int64 // turns that completed without error
TurnsCancelled atomic.Int64 // turns cancelled by user
TokensPrompt atomic.Int64 // cumulative prompt tokens
TokensOutput atomic.Int64 // cumulative output tokens
ToolCalls atomic.Int64 // total tool dispatch attempts
ToolResults atomic.Int64 // tool calls that returned successfully
ToolErrors atomic.Int64 // tool calls that returned errors
ToolDenied atomic.Int64 // tool calls denied by permission gate
CacheHits atomic.Int64 // estimated prefix-cache hits (turns where tokens were >0 and last turn was compacted)
CacheMisses atomic.Int64 // turns where compaction ran (cache was evicted)
ErrorsNonRetry atomic.Int64 // permanent errors (auth, quota)
ErrorsRetry atomic.Int64 // transient errors that were retried
Compactions atomic.Int64 // session compactions performed
Snapshots atomic.Int64 // session snapshots written
Panics atomic.Int64 // goroutine panics recovered
Uptime atomic.Int64 // agent start time unix nano
// Latency histograms are approximated via sum+count for mean calculation.
TurnLatencySum atomic.Int64 // cumulative turn duration in microseconds
TurnLatencyCount atomic.Int64 // number of turns with measured latency
ToolLatencySum atomic.Int64 // cumulative tool duration in microseconds
ToolLatencyCount atomic.Int64 // number of tools with measured latency
}
Registry holds all atomic performance counters.