metrics

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package metrics provides Prometheus metrics for AgentPipe. It tracks agent requests, durations, tokens, costs, and errors.

Index

Constants

View Source
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

func (m *Metrics) RecordAgentCost(agentName, agentType, model string, cost float64)

RecordAgentCost records the estimated cost of an agent request in USD.

func (*Metrics) RecordAgentDuration

func (m *Metrics) RecordAgentDuration(agentName, agentType string, durationSeconds float64)

RecordAgentDuration records the duration of an agent request in seconds.

func (*Metrics) RecordAgentError

func (m *Metrics) RecordAgentError(agentName, agentType, errorType string)

RecordAgentError records an agent error.

func (*Metrics) RecordAgentRequest

func (m *Metrics) RecordAgentRequest(agentName, agentType, status string)

RecordAgentRequest records an agent request with its result.

func (*Metrics) RecordAgentTokens

func (m *Metrics) RecordAgentTokens(agentName, agentType, tokenType string, count int)

RecordAgentTokens records tokens consumed by an agent.

func (*Metrics) RecordConversationTurn

func (m *Metrics) RecordConversationTurn(mode string)

RecordConversationTurn records a conversation turn.

func (*Metrics) RecordMessageSize

func (m *Metrics) RecordMessageSize(agentName, direction string, sizeBytes int)

RecordMessageSize records the size of a message in bytes.

func (*Metrics) RecordRateLimitHit

func (m *Metrics) RecordRateLimitHit(agentName string)

RecordRateLimitHit records a rate limit hit.

func (*Metrics) RecordRetryAttempt

func (m *Metrics) RecordRetryAttempt(agentName, agentType string)

RecordRetryAttempt records a retry attempt.

func (*Metrics) Reset

func (m *Metrics) Reset()

Reset resets all metrics. Useful for testing.

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

func (s *Server) GetMetrics() *Metrics

GetMetrics returns the metrics instance for recording.

func (*Server) GetRegistry

func (s *Server) GetRegistry() *prometheus.Registry

GetRegistry returns the Prometheus registry.

func (*Server) Start

func (s *Server) Start() error

Start starts the metrics server. This method blocks until the server is stopped or encounters an error.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully stops the metrics server.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL