metrics

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 11 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 exposes the Prometheus metrics of a node (FA-OBS-02, ADR 0025 section 7). Every node has its own registry; no collector is global. The metrics carry no tenant or monitor labels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequireToken

func RequireToken(token string, next http.Handler) http.Handler

RequireToken protects next with a static bearer token (FA-OBS-02, ADR 0025). An empty token leaves next unprotected; the separate listener is then the only protection. The comparison takes constant time and does not reveal the token length.

Types

type CheckObserver

type CheckObserver interface {
	CheckStarted(typ string)
	CheckFinished(typ, result string, d time.Duration)
}

CheckObserver receives check start and finish events from the scheduler.

type Metrics

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

Metrics holds the push-side instruments and the scrape-time collector. It implements CheckObserver.

func New

func New(src Sources) *Metrics

New creates the metrics of one node on a private registry.

func (*Metrics) AlertDelivered

func (m *Metrics) AlertDelivered(kind, outcome string)

AlertDelivered counts one alert delivery. kind is the event kind and outcome is e.g. "sent", "failed" or "throttled".

func (*Metrics) CheckFinished

func (m *Metrics) CheckFinished(typ, result string, d time.Duration)

CheckFinished implements CheckObserver.

func (*Metrics) CheckStarted

func (m *Metrics) CheckStarted(string)

CheckStarted implements CheckObserver.

func (*Metrics) Handler

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

Handler serves the metrics of the private registry in the Prometheus text format. It does no authentication; Serve adds the token check.

func (*Metrics) JWKSFetchFailed

func (m *Metrics) JWKSFetchFailed()

JWKSFetchFailed counts one failed fetch of the identity provider's keys.

func (*Metrics) Serve

func (m *Metrics) Serve(ctx context.Context, addr, token string, log *slog.Logger) error

Serve listens on addr and serves only /metrics, protected by token (see RequireToken). It blocks until ctx ends, then shuts down gracefully.

func (*Metrics) UserInfoCalled

func (m *Metrics) UserInfoCalled()

UserInfoCalled counts one userinfo lookup.

func (*Metrics) UserInfoFailed

func (m *Metrics) UserInfoFailed()

UserInfoFailed counts one failed userinfo lookup.

type Sources

type Sources struct {
	// RaftState returns the Raft state, e.g. "Leader" or "Follower".
	RaftState func() string
	// RaftIndexes returns the applied and commit index and the time since the last leader contact.
	RaftIndexes func() (applied, commit uint64, lastContact time.Duration)
	// ReplicationLag maps peer to its lag; a negative value means it never caught up.
	ReplicationLag func() map[string]time.Duration
	// ReplicationDropped maps peer to the number of dropped replication messages.
	ReplicationDropped func() map[string]uint64
	// DBSizes maps the database ("state", "metrics") to its file and WAL size in bytes.
	DBSizes func() map[string]struct{ Size, WAL int64 }
	// DiskFree returns the free ratio of the data directory's file system.
	DiskFree func() (float64, error)
	// OutboxPending returns the number of undelivered notifications. It may block up to the scrape timeout.
	OutboxPending func(ctx context.Context) (int, error)
	// Degraded reports whether the node is in degraded mode (ADR 0024).
	Degraded func() bool
	// SystemAlertsActive maps the alert kind to the number of active system alerts.
	SystemAlertsActive func(ctx context.Context) (map[string]int, error)
	// ClockOffsets maps peer to its clock offset (ADR 0020).
	ClockOffsets func() map[string]time.Duration
	// Version is the build version exported in pulsequorum_build_info.
	Version string
}

Sources are the read-only views the collector takes on each scrape. A nil source means its metrics are not exported. Sources that return an error are left out of that scrape.

Jump to

Keyboard shortcuts

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