metrics

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 FromConfig added in v0.3.0

func FromConfig(
	cfg config.MetricsServer,
	keyDir string,
	name string,
	log *slog.Logger,
) *Server

FromConfig makes the metrics server that cfg turns on, and does not start it. It is nil when cfg turns it off. With TLS on and no cert_file, it serves the self-signed certificate name in keyDir, which it makes.

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").

func Subsystems added in v0.3.0

func Subsystems(
	scs map[string]job.SubComponentInfo,
) []SubsystemStatus

Subsystems returns a SubsystemStatus for each sub-component in scs, for RegisterSubsystems. The status of each one is the status in scs.

Jump to

Keyboard shortcuts

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