metrics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package metrics provides basic metrics collection (counters, timers, gauges).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter is a monotonically increasing counter.

func (*Counter) Add

func (c *Counter) Add(n int64)

Add adds n to the counter.

func (*Counter) Inc

func (c *Counter) Inc()

Inc increments the counter by 1.

func (*Counter) Value

func (c *Counter) Value() int64

Value returns the current value.

type Gauge

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

Gauge is a value that can go up and down.

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) Set

func (g *Gauge) Set(v int64)

Set sets the gauge value.

func (*Gauge) Value

func (g *Gauge) Value() int64

Value returns the current value.

type Registry

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

Registry manages named metrics.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new metrics registry.

func (*Registry) Counter

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

Counter returns or creates a counter.

func (*Registry) Format

func (r *Registry) Format() string

Format returns a formatted string of all metrics.

func (*Registry) Gauge

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

Gauge returns or creates a gauge.

func (*Registry) Snapshot

func (r *Registry) Snapshot() map[string]interface{}

Snapshot returns a snapshot of all metrics.

func (*Registry) Timer

func (r *Registry) Timer(name string) *Timer

Timer returns or creates a timer.

type Timer

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

Timer tracks timing information.

func NewTimer

func NewTimer() *Timer

NewTimer creates a new timer.

func (*Timer) Record

func (t *Timer) Record(d time.Duration)

Record records a duration.

func (*Timer) Stats

func (t *Timer) Stats() TimerStats

Stats returns timer statistics.

func (*Timer) Time

func (t *Timer) Time(fn func()) time.Duration

Time executes fn and records its duration.

type TimerStats

type TimerStats struct {
	Count int64         `json:"count"`
	Total time.Duration `json:"total"`
	Mean  time.Duration `json:"mean"`
	Min   time.Duration `json:"min"`
	Max   time.Duration `json:"max"`
}

TimerStats represents timer statistics.

type ToolAggregate added in v0.2.0

type ToolAggregate struct {
	CallCount  int
	TotalBytes int64
	TotalMs    int64
	Errors     int
}

ToolAggregate holds per-tool aggregate statistics collected during a session.

type ToolAggregator added in v0.2.0

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

ToolAggregator collects per-tool call statistics in a thread-safe manner. Inspired by herm's TraceToolSummary pattern for per-tool aggregates.

func NewToolAggregator added in v0.2.0

func NewToolAggregator() *ToolAggregator

NewToolAggregator creates a new ToolAggregator ready for use.

func (*ToolAggregator) All added in v0.2.0

func (a *ToolAggregator) All() map[string]*ToolAggregate

All returns a snapshot of all tool aggregates. The returned map is a copy.

func (*ToolAggregator) Get added in v0.2.0

func (a *ToolAggregator) Get(toolName string) *ToolAggregate

Get returns the aggregate for a specific tool, or nil if not recorded.

func (*ToolAggregator) Record added in v0.2.0

func (a *ToolAggregator) Record(toolName string, bytes int64, durationMs int64, isError bool)

Record records a tool invocation with its byte count, duration, and error status.

func (*ToolAggregator) Reset added in v0.2.0

func (a *ToolAggregator) Reset()

Reset clears all recorded tool aggregates.

type ToolExecution added in v0.2.0

type ToolExecution struct {
	Name      string
	StartTime time.Time
	Duration  time.Duration
	Success   bool
	Error     string
}

ToolExecution records a single tool invocation.

type ToolMetrics added in v0.2.0

type ToolMetrics struct {
	Name          string
	Calls         int
	Failures      int
	TotalDuration time.Duration
}

ToolMetrics holds per-tool metrics.

func (*ToolMetrics) AvgDuration added in v0.2.0

func (m *ToolMetrics) AvgDuration() time.Duration

AvgDuration returns average call duration for a tool.

func (*ToolMetrics) SuccessRate added in v0.2.0

func (m *ToolMetrics) SuccessRate() float64

SuccessRate returns the success rate for a tool.

type ToolMonitor added in v0.2.0

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

ToolMonitor tracks real-time tool execution metrics.

func NewToolMonitor added in v0.2.0

func NewToolMonitor() *ToolMonitor

NewToolMonitor creates a new monitor.

func (*ToolMonitor) End added in v0.2.0

func (tm *ToolMonitor) End(name, callID string, success bool, errMsg string)

End records the completion of a tool call.

func (*ToolMonitor) Start added in v0.2.0

func (tm *ToolMonitor) Start(name, callID string)

Start records the beginning of a tool call.

func (*ToolMonitor) Stats added in v0.2.0

func (tm *ToolMonitor) Stats() ToolStats

Stats returns aggregated metrics.

type ToolStats added in v0.2.0

type ToolStats struct {
	TotalCalls    int
	SuccessCalls  int
	FailedCalls   int
	ActiveCalls   int
	TotalDuration time.Duration
	PerTool       map[string]*ToolMetrics
}

ToolStats holds aggregated tool metrics.

Jump to

Keyboard shortcuts

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