Documentation
¶
Overview ¶
Package metrics provides Prometheus metrics for AgentPipe. It tracks agent requests, durations, tokens, costs, and errors.
Index ¶
- Constants
- type Metrics
- func (m *Metrics) DecrementActiveConversations()
- func (m *Metrics) IncrementActiveConversations()
- func (m *Metrics) RecordAgentCost(agentName, agentType, model string, cost float64)
- func (m *Metrics) RecordAgentDuration(agentName, agentType string, durationSeconds float64)
- func (m *Metrics) RecordAgentError(agentName, agentType, errorType string)
- func (m *Metrics) RecordAgentRequest(agentName, agentType, status string)
- func (m *Metrics) RecordAgentTokens(agentName, agentType, tokenType string, count int)
- func (m *Metrics) RecordConversationTurn(mode string)
- func (m *Metrics) RecordMessageSize(agentName, direction string, sizeBytes int)
- func (m *Metrics) RecordRateLimitHit(agentName string)
- func (m *Metrics) RecordRetryAttempt(agentName, agentType string)
- func (m *Metrics) Reset()
- type Server
- type ServerConfig
Constants ¶
const (
// Namespace is the Prometheus namespace for all AgentPipe metrics
Namespace = "agentpipe"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶
type Metrics struct {
// AgentRequests counts total agent requests by agent name and status (success/error)
AgentRequests *prometheus.CounterVec
// AgentRequestDuration tracks agent request duration in seconds
AgentRequestDuration *prometheus.HistogramVec
// AgentTokens counts tokens consumed by agent and type (input/output)
AgentTokens *prometheus.CounterVec
// AgentCost tracks estimated costs in USD by agent
AgentCost *prometheus.CounterVec
// AgentErrors counts errors by agent and error type
AgentErrors *prometheus.CounterVec
// ActiveConversations tracks the number of active conversations
ActiveConversations prometheus.Gauge
// ConversationTurns counts total conversation turns by mode
ConversationTurns *prometheus.CounterVec
// MessageSize tracks message size distribution in bytes
MessageSize *prometheus.HistogramVec
// RetryAttempts counts retry attempts by agent
RetryAttempts *prometheus.CounterVec
// RateLimitHits counts rate limit hits by agent
RateLimitHits *prometheus.CounterVec
}
Metrics contains all Prometheus metrics for AgentPipe.
var ( // DefaultMetrics is the default global metrics instance DefaultMetrics *Metrics // DefaultRegistry is the default Prometheus registry DefaultRegistry *prometheus.Registry )
func NewMetrics ¶
func NewMetrics(registry prometheus.Registerer) *Metrics
NewMetrics creates a new Metrics instance with the given registry. If registry is nil, the default Prometheus registry is used.
func (*Metrics) DecrementActiveConversations ¶
func (m *Metrics) DecrementActiveConversations()
DecrementActiveConversations decrements the active conversations gauge.
func (*Metrics) IncrementActiveConversations ¶
func (m *Metrics) IncrementActiveConversations()
IncrementActiveConversations increments the active conversations gauge.
func (*Metrics) RecordAgentCost ¶
RecordAgentCost records the estimated cost of an agent request in USD.
func (*Metrics) RecordAgentDuration ¶
RecordAgentDuration records the duration of an agent request in seconds.
func (*Metrics) RecordAgentError ¶
RecordAgentError records an agent error.
func (*Metrics) RecordAgentRequest ¶
RecordAgentRequest records an agent request with its result.
func (*Metrics) RecordAgentTokens ¶
RecordAgentTokens records tokens consumed by an agent.
func (*Metrics) RecordConversationTurn ¶
RecordConversationTurn records a conversation turn.
func (*Metrics) RecordMessageSize ¶
RecordMessageSize records the size of a message in bytes.
func (*Metrics) RecordRateLimitHit ¶
RecordRateLimitHit records a rate limit hit.
func (*Metrics) RecordRetryAttempt ¶
RecordRetryAttempt records a retry attempt.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP server that exposes Prometheus metrics.
func NewServer ¶
func NewServer(config ServerConfig) *Server
NewServer creates a new metrics server with the given configuration.
func (*Server) GetMetrics ¶
GetMetrics returns the metrics instance for recording.
func (*Server) GetRegistry ¶
func (s *Server) GetRegistry() *prometheus.Registry
GetRegistry returns the Prometheus registry.
type ServerConfig ¶
type ServerConfig struct {
// Addr is the address to listen on (e.g., ":9090")
Addr string
// ReadTimeout is the maximum duration for reading the entire request
ReadTimeout time.Duration
// WriteTimeout is the maximum duration before timing out writes
WriteTimeout time.Duration
// Registry is the Prometheus registry to use (if nil, a new one is created)
Registry *prometheus.Registry
}
ServerConfig contains configuration for the metrics server.