metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package metrics is the private port: Prometheus counters and pprof, bound to loopback and nothing else.

It is a separate listener rather than a route on the public server because the two have different audiences. The public port is the internet; this one is the operator's own machine, and putting a profiler behind the same timeouts and the same address as a driver's upload would be a mistake in both directions.

There is no vendor here and no agent to install. An operator who wants dashboards points their own Prometheus at this port; one who does not, does not notice it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

type Registry struct {

	// Requests counts finished HTTP requests by route and status.
	Requests *prometheus.CounterVec
	// RequestDuration is how long they took.
	RequestDuration *prometheus.HistogramVec
	// SetupAttempts counts setup token attempts, by outcome. It is the signal
	// that someone is guessing at a server that has not been set up yet.
	SetupAttempts *prometheus.CounterVec
	// AdminLogins counts admin sign-in attempts, by outcome.
	AdminLogins *prometheus.CounterVec
	// DatabasePoolConns reports the pool's state, sampled when scraped.
	DatabasePoolConns *prometheus.GaugeVec
	// contains filtered or unexported fields
}

Registry is this server's metrics. It is its own registry rather than the default one, so that a dependency registering a collector cannot silently change what this server publishes.

func New

func New() *Registry

New builds the registry with the process and Go collectors already in it.

func (*Registry) Handler

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

Handler serves /metrics and the pprof endpoints. It is only ever mounted on the loopback listener; internal/config refuses a metrics address that is not a loopback one, so this cannot be exposed by a configuration mistake.

func (*Registry) Observe

func (m *Registry) Observe(route string, status int, took time.Duration)

Observe records one finished request. route is the ServeMux pattern rather than the path, so a page per driver does not become a metric per driver.

func (*Registry) SamplePool

func (m *Registry) SamplePool(acquired, idle, total int32)

SamplePool records the database pool's state.

func (*Registry) SamplePoolEvery

func (m *Registry) SamplePoolEvery(ctx context.Context, every time.Duration, sample func() (acquired, idle, total int32))

SamplePoolEvery keeps the pool gauges fresh until ctx is cancelled. It is a goroutine the caller owns, and it returns when the context does.

Jump to

Keyboard shortcuts

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