metrics

package
v0.0.0-...-86e7852 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package metrics provides a lightweight HTTP server for per-component Prometheus metrics with isolated registries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is a per-component HTTP server that serves /metrics, /health, and /health/ready with an isolated Prometheus registry and OTEL MeterProvider.

func New

func New(
	host string,
	port int,
	logger *slog.Logger,
) *Server

New creates a new metrics server on the given port with an isolated Prometheus registry and OTEL MeterProvider.

func (*Server) MeterProvider

func (s *Server) MeterProvider() *sdkmetric.MeterProvider

MeterProvider returns the isolated OTEL MeterProvider for this server. Components use this to create instruments that appear on this server's /metrics endpoint.

func (*Server) RegisterHeartbeatAge

func (s *Server) RegisterHeartbeatAge(
	timeFn func() time.Time,
)

RegisterHeartbeatAge registers an osapi_heartbeat_age_seconds gauge that reports the time since the last successful heartbeat write. The timeFn should return the timestamp of the last heartbeat, or zero time if none.

func (*Server) RegisterSubsystems

func (s *Server) RegisterSubsystems(
	subsystems []SubsystemStatus,
)

RegisterSubsystems registers an osapi_subsystem_up gauge that reports 1 when each subsystem status function returns "ok" and 0 otherwise. All subsystems are emitted in a single callback with a "subsystem" attribute.

func (*Server) SetReadinessFunc

func (s *Server) SetReadinessFunc(
	fn func() error,
)

SetReadinessFunc sets a function called by /health/ready to determine whether this component is ready to serve traffic. If fn returns an error the endpoint responds 503; if nil it responds 200.

func (*Server) Start

func (s *Server) Start()

Start starts the HTTP server in a background goroutine.

func (*Server) Stop

func (s *Server) Stop(
	ctx context.Context,
)

Stop gracefully shuts down the HTTP server and meter provider.

type SubsystemStatus

type SubsystemStatus struct {
	Name     string
	StatusFn func() string
}

SubsystemStatus holds a subsystem name and a function that returns its current status string (e.g., "ok", "disabled", "error").

Jump to

Keyboard shortcuts

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