metrics

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package metrics provides daemon-wide atomic counters for observability. Distinct from supervisor.Metrics which tracks per-process ring-buffer stats; this package tracks daemon-level aggregate counters.

Index

Constants

View Source
const (
	ReapReasonClientDisconnected = "client_disconnected"
	ReapReasonIdleTimeout        = "idle_timeout"
	ReapReasonUpstreamDelete     = "upstream_delete"
	ReapReasonSessionRemoved     = "session_removed"
	ReapReasonHealthCheck        = "health_check"
	ReapReasonToolsListFailed    = "tools_list_failed"
	ReapReasonProcessLost        = "process_lost"
	ReapReasonListenerClosed     = "listener_closed"
	ReapReasonUnknown            = "unknown"
)

Variables

This section is empty.

Functions

func NormalizeReapReason added in v1.2.5

func NormalizeReapReason(reason string) string

NormalizeReapReason maps legacy close reason text to canonical metrics keys. Unknown input collapses to "unknown" to avoid unbounded metric cardinality.

Types

type DaemonMetrics

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

DaemonMetrics provides thread-safe daemon-wide counters using sync/atomic.

func NewDaemonMetrics

func NewDaemonMetrics() *DaemonMetrics

NewDaemonMetrics creates a new zeroed DaemonMetrics.

func (*DaemonMetrics) DecSessionsActive

func (m *DaemonMetrics) DecSessionsActive()

DecSessionsActive atomically decrements the active session counter.

func (*DaemonMetrics) DecSubprocessesActive

func (m *DaemonMetrics) DecSubprocessesActive()

DecSubprocessesActive atomically decrements the active subprocess counter.

func (*DaemonMetrics) IncErrors

func (m *DaemonMetrics) IncErrors()

IncErrors atomically increments the error counter.

func (*DaemonMetrics) IncSessionsActive

func (m *DaemonMetrics) IncSessionsActive()

IncSessionsActive atomically increments the active session counter.

func (*DaemonMetrics) IncSubprocessesActive

func (m *DaemonMetrics) IncSubprocessesActive()

IncSubprocessesActive atomically increments the active subprocess counter.

func (*DaemonMetrics) IncToolCalls

func (m *DaemonMetrics) IncToolCalls()

IncToolCalls atomically increments the tool call counter.

func (*DaemonMetrics) Snapshot

func (m *DaemonMetrics) Snapshot() Snapshot

Snapshot returns a point-in-time copy of all counters.

type ServerMetrics added in v1.2.5

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

ServerMetrics provides thread-safe per-server counters using sync/atomic. Tracks active sessions, reap counts by reason, and admission denials.

func NewServerMetrics added in v1.2.5

func NewServerMetrics() *ServerMetrics

NewServerMetrics creates a new zeroed ServerMetrics.

func (*ServerMetrics) DecActiveSessions added in v1.2.5

func (m *ServerMetrics) DecActiveSessions()

DecActiveSessions atomically decrements the active session counter.

func (*ServerMetrics) IncActiveSessions added in v1.2.5

func (m *ServerMetrics) IncActiveSessions()

IncActiveSessions atomically increments the active session counter.

func (*ServerMetrics) IncAdmissionDenied added in v1.2.5

func (m *ServerMetrics) IncAdmissionDenied()

IncAdmissionDenied atomically increments the admission denial counter.

func (*ServerMetrics) IncReaped added in v1.2.5

func (m *ServerMetrics) IncReaped(reason string)

IncReaped increments the reap counter for the given reason. Reasons are normalized to bounded canonical keys before counting.

func (*ServerMetrics) Snapshot added in v1.2.5

func (m *ServerMetrics) Snapshot() ServerMetricsSnapshot

Snapshot returns a point-in-time copy of all per-server counters.

type ServerMetricsReporter added in v1.2.5

type ServerMetricsReporter interface {
	IncActiveSessions()
	DecActiveSessions()
	IncAdmissionDenied()
	IncReaped(reason string)
}

ServerMetricsReporter decouples consumers from concrete ServerMetrics. SharedSessionManager uses this interface so tests can inject stubs.

type ServerMetricsSnapshot added in v1.2.5

type ServerMetricsSnapshot struct {
	ActiveSessions  int64            `json:"active_sessions"`
	ReapedByReason  map[string]int64 `json:"reaped_by_reason"`
	AdmissionDenied int64            `json:"admission_denied"`
}

ServerMetricsSnapshot holds a point-in-time copy of per-server metrics.

type Snapshot

type Snapshot struct {
	ToolCallsTotal     int64 `json:"tool_calls_total"`
	ErrorsTotal        int64 `json:"errors_total"`
	SessionsActive     int64 `json:"sessions_active"`
	SubprocessesActive int64 `json:"subprocesses_active"`
}

Snapshot holds a point-in-time copy of daemon metrics.

Jump to

Keyboard shortcuts

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