Help us shape the future of Go! Take the 2026 Go Developer Survey

metrics

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package metrics implements an in-process metrics sink for the rysh agentic system. It satisfies rysh-shared/agentic.MetricsSink and exposes a simple text dump usable from `##agent metrics`.

Follow-up item 3, MVP form: in-memory aggregation. A Prometheus exporter is a natural drop-in via the same interface (add a PrometheusSink that wraps client_golang's Registry); kept out of this commit to avoid pulling in a new dependency.

Prometheus exporter for the agentic MetricsSink (follow-up 3b).

PromSink is a drop-in MetricsSink that records into a private prometheus.Registry; the daemon serves it on /metrics behind the metrics config flag. It composes with the in-process Sink via Multi so ##agent metrics keeps working alongside scraping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Multi

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

Multi fans every MetricsSink call out to several sinks (e.g. the in-process Sink for ##agent metrics plus a PromSink for scraping). It exposes Dump() by delegating to a designated dumper (the in-process Sink), so the existing ##agent metrics command keeps working when Prometheus is enabled.

func NewMulti

func NewMulti(primary *Sink, extra ...sharedagentic.MetricsSink) *Multi

NewMulti builds a fan-out. primary (the in-process Sink) is always first and is used for Dump(); extra sinks are appended. primary may be nil.

func (*Multi) Dump

func (m *Multi) Dump() string

Dump delegates to the in-process Sink so ##agent metrics keeps working.

func (*Multi) RecordApproval

func (m *Multi) RecordApproval(toolName, decision string, dur time.Duration)

RecordApproval implements sharedagentic.MetricsSink.

func (*Multi) RecordCompaction

func (m *Multi) RecordCompaction(droppedTurns int, dur time.Duration)

RecordCompaction implements sharedagentic.MetricsSink.

func (*Multi) RecordLLMCall

func (m *Multi) RecordLLMCall(model string, dur time.Duration, usage provider.Usage)

RecordLLMCall implements sharedagentic.MetricsSink.

func (*Multi) RecordTool

func (m *Multi) RecordTool(name string, dur time.Duration, out *sharedtools.ToolOutput, err error)

RecordTool implements sharedagentic.MetricsSink.

type PromSink

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

PromSink implements sharedagentic.MetricsSink by recording into a private Prometheus registry. Use Handler() to serve it. Safe for concurrent use (Prometheus collectors are internally synchronised).

func NewPrometheus

func NewPrometheus() *PromSink

NewPrometheus builds a PromSink with all collectors registered into a fresh private registry (no global state; the /metrics output is rysh-only).

func (*PromSink) Handler

func (p *PromSink) Handler() http.Handler

Handler returns an http.Handler that serves this sink's registry in Prometheus text format.

func (*PromSink) RecordApproval

func (p *PromSink) RecordApproval(toolName, decision string, dur time.Duration)

RecordApproval implements sharedagentic.MetricsSink.

func (*PromSink) RecordCompaction

func (p *PromSink) RecordCompaction(droppedTurns int, dur time.Duration)

RecordCompaction implements sharedagentic.MetricsSink.

func (*PromSink) RecordLLMCall

func (p *PromSink) RecordLLMCall(model string, dur time.Duration, usage provider.Usage)

RecordLLMCall implements sharedagentic.MetricsSink.

func (*PromSink) RecordTool

func (p *PromSink) RecordTool(name string, dur time.Duration, out *sharedtools.ToolOutput, err error)

RecordTool implements sharedagentic.MetricsSink.

type Sink

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

Sink is an in-process MetricsSink. Safe for concurrent use.

func New

func New() *Sink

New constructs a fresh in-memory sink.

func (*Sink) Dump

func (s *Sink) Dump() string

Dump returns a human-readable text summary of accumulated metrics. Used by the `##agent metrics` command.

func (*Sink) RecordApproval

func (s *Sink) RecordApproval(toolName, decision string, dur time.Duration)

RecordApproval implements agentic.MetricsSink.

func (*Sink) RecordCompaction

func (s *Sink) RecordCompaction(droppedTurns int, dur time.Duration)

RecordCompaction implements agentic.MetricsSink.

func (*Sink) RecordLLMCall

func (s *Sink) RecordLLMCall(model string, dur time.Duration, usage provider.Usage)

RecordLLMCall implements agentic.MetricsSink.

func (*Sink) RecordTool

func (s *Sink) RecordTool(name string, dur time.Duration, out *sharedtools.ToolOutput, err error)

RecordTool implements agentic.MetricsSink.

Jump to

Keyboard shortcuts

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