metrics

package
v0.6.19 Latest Latest
Warning

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

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

Documentation

Overview

Package metrics exposes the agent's Prometheus collectors and a small HTTP server that serves /metrics. The collectors live in their own Registry rather than the global default so multiple agents in the same test process do not collide.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	Connected           *prometheus.GaugeVec // labels: endpoint
	ReconnectsTotal     prometheus.Counter
	EventsEmittedTotal  *prometheus.CounterVec // labels: type
	EventsDroppedTotal  *prometheus.CounterVec // labels: type, reason
	BufferSize          *prometheus.GaugeVec   // labels: type
	ActiveSubscriptions prometheus.Gauge
	HeartbeatsSent      prometheus.Counter
	StreamErrorsTotal   *prometheus.CounterVec // labels: stage
	// contains filtered or unexported fields
}

Metrics holds every collector the agent updates. Construct once via New and pass it down. Concurrency-safe by design (Prometheus collectors are).

func New

func New() *Metrics

New returns a fully wired Metrics with all collectors registered in a fresh registry.

func (*Metrics) Handler

func (m *Metrics) Handler() http.Handler

Handler returns a stand-alone /metrics http.Handler. Use Server to mount it on a private port; use Handler directly to embed it in another mux.

func (*Metrics) Registry

func (m *Metrics) Registry() *prometheus.Registry

Registry returns the underlying Prometheus registry. Useful for tests and for callers that want to expose admin-agent metrics from their own HTTP server (the framework's main /metrics, for example) instead of running the agent's standalone server.

type Server

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

Server is a tiny HTTP server that serves /metrics and /healthz.

func NewServer

func NewServer(addr string, m *Metrics, logger *slog.Logger) *Server

NewServer constructs a metrics server. addr is a [host]:port string (e.g. ":9101", "127.0.0.1:9101"). Empty addr disables the server (Run returns immediately).

func (*Server) Run

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

Run starts the server and blocks until ctx is cancelled. It returns nil on graceful shutdown, non-nil on listen errors. Safe to call when the server has no addr — then it is a no-op that just waits on ctx.

Jump to

Keyboard shortcuts

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