metrics

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package metrics provides application metrics collection.

Index

Constants

This section is empty.

Variables

View Source
var (
	// HTTP metrics
	HTTPRequestsTotal     = NewCounter("http_requests_total")
	HTTPRequestDuration   = NewHistogram("http_request_duration_seconds", DefaultBuckets())
	HTTPActiveConnections = NewGauge("http_active_connections")

	// LLM metrics
	LLMRequestsTotal   = NewCounter("llm_requests_total")
	LLMRequestDuration = NewHistogram("llm_request_duration_seconds", DefaultBuckets())
	LLMTokensTotal     = NewCounter("llm_tokens_total")
	LLMSlowRequests    = NewCounter("llm_slow_requests_total")

	// Database metrics
	DBQueriesTotal    = NewCounter("db_queries_total")
	DBQueryDuration   = NewHistogram("db_query_duration_seconds", DefaultBuckets())
	DBConnectionsOpen = NewGauge("db_connections_open")

	// Memory metrics
	MemorySessionsActive = NewGauge("memory_sessions_active")
	MemoryMessagesTotal  = NewCounter("memory_messages_total")

	// Workforce metrics
	WorkforceActive     = NewGauge("workforce_active")
	WorkforceTasksTotal = NewCounter("workforce_tasks_total")

	// Token consumption metrics
	// Labels: model, type (input/output), feature
	AITokensTotal = NewCounter("ai_tokens_total")

	// Cost tracking in cents (for budget monitoring)
	// Labels: model, feature
	AICostCents = NewCounter("ai_cost_cents")

	// Time to first token for streaming responses
	AITimeToFirstToken = NewHistogram("ai_time_to_first_token_seconds",
		[]float64{0.1, 0.25, 0.5, 1, 2, 5, 10})

	// Agent execution metrics
	// Labels: agent_type, status (success/failure)
	AgentToolCallsTotal = NewCounter("agent_tool_calls_total")
	AgentStepsPerTask   = NewHistogram("agent_steps_per_task",
		[]float64{1, 2, 3, 5, 10, 20, 50})

	// User feedback metrics
	// Labels: feedback_type (thumbs_up/thumbs_down/edit)
	AIUserFeedbackTotal = NewCounter("ai_user_feedback_total")

	// ThinkFlow metrics
	ThinkFlowExecutionsTotal = NewCounter("thinkflow_executions_total")
	ThinkFlowDuration        = NewHistogram("thinkflow_duration_seconds", DefaultBuckets())
	ThinkFlowRetriesTotal    = NewCounter("thinkflow_retries_total")

	// Skill execution metrics
	SkillCallsTotal    = NewCounter("skill_calls_total")
	SkillCallDuration  = NewHistogram("skill_call_duration_seconds", DefaultBuckets())
	SkillFailuresTotal = NewCounter("skill_failures_total")
)
View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the global default registry.

Functions

func DefaultBuckets

func DefaultBuckets() []float64

DefaultBuckets returns default latency buckets in seconds.

func PrometheusHandler

func PrometheusHandler() func(w io.Writer)

PrometheusHandler returns a http.HandlerFunc for /metrics endpoint.

func RecordAgentSteps

func RecordAgentSteps(steps float64)

RecordAgentSteps records the number of steps taken to complete a task.

func RecordCost

func RecordCost(model, feature string, cents uint64)

RecordCost records cost in cents for an AI request.

func RecordSkillCall

func RecordSkillCall(skillName string, durationSec float64, success bool)

RecordSkillCall records a skill invocation.

func RecordTTFT

func RecordTTFT(seconds float64)

RecordTTFT records time to first token for a streaming response.

func RecordThinkFlowExecution

func RecordThinkFlowExecution(durationSec float64)

RecordThinkFlowExecution records a ThinkFlow execution.

func RecordThinkFlowRetry

func RecordThinkFlowRetry()

RecordThinkFlowRetry records a ThinkFlow retry.

func RecordTokens

func RecordTokens(model, tokenType, feature string, count uint64)

RecordTokens records token consumption for an AI request.

func RecordToolCall

func RecordToolCall(agentType, status string)

RecordToolCall records a tool/skill call by an agent.

func RecordUserFeedback

func RecordUserFeedback(feedbackType string)

RecordUserFeedback records user feedback on AI response.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter is a monotonically increasing counter.

func Counter_

func Counter_(name string, tags ...string) *Counter

Counter creates or returns a counter.

func NewCounter

func NewCounter(name string, tags ...string) *Counter

NewCounter creates a new counter with name and optional tags.

func (*Counter) Add

func (c *Counter) Add(delta uint64)

Add adds delta to the counter.

func (*Counter) Inc

func (c *Counter) Inc()

Inc increments the counter by 1.

func (*Counter) Name

func (c *Counter) Name() string

Name returns the counter name.

func (*Counter) Tags

func (c *Counter) Tags() map[string]string

Tags returns the counter tags.

func (*Counter) Value

func (c *Counter) Value() uint64

Value returns the current counter value.

func (*Counter) WithLabels

func (c *Counter) WithLabels(labels ...string) *Counter

WithLabels returns a new counter with additional labels.

type Gauge

type Gauge struct {
	// contains filtered or unexported fields
}

Gauge is a value that can increase and decrease.

func Gauge_

func Gauge_(name string, tags ...string) *Gauge

Gauge creates or returns a gauge.

func NewGauge

func NewGauge(name string, tags ...string) *Gauge

NewGauge creates a new gauge with name and optional tags.

func (*Gauge) Add

func (g *Gauge) Add(delta int64)

Add adds delta to the gauge.

func (*Gauge) Dec

func (g *Gauge) Dec()

Dec decrements the gauge by 1.

func (*Gauge) Inc

func (g *Gauge) Inc()

Inc increments the gauge by 1.

func (*Gauge) Name

func (g *Gauge) Name() string

Name returns the gauge name.

func (*Gauge) Set

func (g *Gauge) Set(value int64)

Set sets the gauge value.

func (*Gauge) Tags

func (g *Gauge) Tags() map[string]string

Tags returns the gauge tags.

func (*Gauge) Value

func (g *Gauge) Value() int64

Value returns the current gauge value.

type Histogram

type Histogram struct {
	// contains filtered or unexported fields
}

Histogram tracks distribution of values.

func Histogram_

func Histogram_(name string, buckets []float64, tags ...string) *Histogram

Histogram creates or returns a histogram.

func NewHistogram

func NewHistogram(name string, buckets []float64, tags ...string) *Histogram

NewHistogram creates a new histogram with name and buckets.

func (*Histogram) Count

func (h *Histogram) Count() uint64

Count returns the count of observations.

func (*Histogram) Name

func (h *Histogram) Name() string

Name returns the histogram name.

func (*Histogram) NewTimer

func (h *Histogram) NewTimer() *Timer

NewTimer starts a new timer for the histogram.

func (*Histogram) Observe

func (h *Histogram) Observe(value float64)

Observe records a value.

func (*Histogram) Sum

func (h *Histogram) Sum() float64

Sum returns the sum of all observed values.

func (*Histogram) Tags

func (h *Histogram) Tags() map[string]string

Tags returns the histogram tags.

type HistogramSnapshot

type HistogramSnapshot struct {
	Count uint64
	Sum   float64
}

HistogramSnapshot contains histogram data.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds all registered metrics.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new metrics registry.

func (*Registry) GetCounter

func (r *Registry) GetCounter(name string) *Counter

GetCounter returns a counter by name.

func (*Registry) GetGauge

func (r *Registry) GetGauge(name string) *Gauge

GetGauge returns a gauge by name.

func (*Registry) GetHistogram

func (r *Registry) GetHistogram(name string) *Histogram

GetHistogram returns a histogram by name.

func (*Registry) RegisterCounter

func (r *Registry) RegisterCounter(c *Counter)

RegisterCounter registers a counter in the registry.

func (*Registry) RegisterGauge

func (r *Registry) RegisterGauge(g *Gauge)

RegisterGauge registers a gauge in the registry.

func (*Registry) RegisterHistogram

func (r *Registry) RegisterHistogram(h *Histogram)

RegisterHistogram registers a histogram in the registry.

func (*Registry) Snapshot

func (r *Registry) Snapshot() *Snapshot

Snapshot returns current values of all metrics.

func (*Registry) WritePrometheus

func (r *Registry) WritePrometheus(w io.Writer) error

WritePrometheus writes metrics in Prometheus text format.

type Snapshot

type Snapshot struct {
	Counters   map[string]uint64
	Gauges     map[string]int64
	Histograms map[string]HistogramSnapshot
}

Snapshot returns a snapshot of all metrics.

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

Timer measures duration and records to histogram.

func (*Timer) ObserveDuration

func (t *Timer) ObserveDuration() time.Duration

ObserveDuration records the elapsed time since timer start.

Jump to

Keyboard shortcuts

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