Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AvailableTokenTypes = []TokenType{ TokenTypeInput, TokenTypeOutput, TokenTypeCacheRead, TokenTypeCacheCreation, }
AvailableTokenTypes is the closed set of token types. Iterating it is what guarantees every label combination is pre-initialized, so rate() evaluates to zero rather than no-data before the first job runs.
Functions ¶
func BuildJobMetricsName ¶
BuildJobMetricsName returns the standardized PushGateway job name for an agent job binary. All agent binaries must use this function to ensure the job name is consistent across deployments.
Example: BuildJobMetricsName("claude-agent") → "agent_job_claude_agent"
Types ¶
type JobMetrics ¶
type JobMetrics interface {
// RecordRun atomically increments the run counter and sets the last-run
// gauge for the given status label. Both operations use the same label
// value; they cannot drift.
RecordRun(status agentlib.AgentStatus)
// RecordDuration observes the run duration histogram.
RecordDuration(d time.Duration)
// RecordUsage records the token and turn summary of a finished job: each
// token count advances its own type-labelled series and the turn count
// advances the turn counter. A negative value is skipped for that counter
// only; the other counters in the same call still record.
RecordUsage(usage JobUsage)
}
JobMetrics records per-job Prometheus metrics at the result-publish boundary.
func NewJobMetrics ¶
func NewJobMetrics( registry *prometheus.Registry, currentDateTime libtime.CurrentDateTime, ) JobMetrics
NewJobMetrics creates a JobMetrics that registers five collectors onto the caller-owned registry. The caller must NOT pass nil for registry. Registration failures (e.g. duplicate registration) panic — they are programmer errors caught at startup.
type JobUsage ¶ added in v0.80.0
type JobUsage struct {
// InputTokens is the count of fresh (non-cached) input tokens the job consumed.
InputTokens int64
// OutputTokens is the count of output tokens the job produced.
OutputTokens int64
// CacheReadTokens is the count of input tokens served from the prompt cache.
CacheReadTokens int64
// CacheCreationTokens is the count of input tokens written into the prompt cache.
CacheCreationTokens int64
// Turns is the number of conversation turns the job took.
Turns int64
}
JobUsage is the LLM token and turn summary of one finished agent job. The zero value is valid and records nothing but zeros.
type TokenType ¶ added in v0.80.0
type TokenType string
TokenType is the value of the type label on agent_job_tokens_total. The set is closed: no caller-supplied or session-supplied value ever becomes a label, so the family's cardinality is fixed at len(AvailableTokenTypes) series.
const ( // TokenTypeInput counts fresh (non-cached) input tokens. TokenTypeInput TokenType = "input" // TokenTypeOutput counts generated output tokens. TokenTypeOutput TokenType = "output" // TokenTypeCacheRead counts input tokens served from the prompt cache. TokenTypeCacheRead TokenType = "cache_read" // TokenTypeCacheCreation counts input tokens written into the prompt cache. TokenTypeCacheCreation TokenType = "cache_creation" )