metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package metrics defines the Prometheus collectors of a Foreman client, the shared histogram buckets, and label capping for values derived from user data.

m, err := metrics.New(prometheus.DefaultRegisterer)
m.Inserted.WithLabelValues(m.Queue(q), m.Kind(k)).Inc()

Index

Constants

View Source
const DefaultLabelCap = 50

DefaultLabelCap is the number of distinct user-derived label values (queue, kind, periodic name) kept per metric before others map to "other".

View Source
const Other = "other"

Other replaces label values beyond the cap.

Variables

View Source
var (
	// DurationBuckets covers job run times from 1 ms to ~1 h.
	DurationBuckets = []float64{
		0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 300, 900, 3600,
	}
	// LatencyBuckets covers queue latency (scheduled_at to attempted_at) from 1 ms to 1 h.
	LatencyBuckets = []float64{
		0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 300, 3600,
	}
	// FetchBuckets covers fetch statements from 100 µs to 5 s.
	FetchBuckets = []float64{0.0001, 0.00025, 0.0005, 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 1, 5}
)

Histogram buckets, declared once for the project.

Functions

This section is empty.

Types

type Capper

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

Capper bounds the distinct values of a label: the first Max values are kept, later ones become "other".

func NewCapper

func NewCapper(maxValues int) *Capper

NewCapper returns a capper keeping up to maxValues values.

func (*Capper) Value

func (c *Capper) Value(v string) string

Value returns v if it is (or can become) one of the kept values, else Other.

type Metrics

type Metrics struct {
	Inserted        *prometheus.CounterVec
	Completed       *prometheus.CounterVec
	Duration        *prometheus.HistogramVec
	QueueLatency    *prometheus.HistogramVec
	QueueDepth      *prometheus.GaugeVec
	Running         *prometheus.GaugeVec
	Leader          prometheus.Gauge
	Rescued         prometheus.Counter
	Stale           prometheus.Counter
	PeriodicSkipped *prometheus.CounterVec
	Unserved        *prometheus.CounterVec
	FetchDuration   *prometheus.HistogramVec
	MaintenanceRun  *prometheus.GaugeVec
	MaintenanceRows *prometheus.CounterVec
	BuildInfo       *prometheus.GaugeVec
	// contains filtered or unexported fields
}

Metrics holds every Prometheus collector of a client.

func New

func New(reg prometheus.Registerer) (*Metrics, error)

New creates the collectors and registers them with reg. A nil reg keeps them in a private registry. Collectors already registered by another client in the same process are shared, so several clients may use one registerer.

func (*Metrics) Kind

func (m *Metrics) Kind(k string) string

Kind caps a kind label value.

func (*Metrics) Name

func (m *Metrics) Name(n string) string

Name caps a periodic job name label value.

func (*Metrics) ObserveMaintenance

func (m *Metrics) ObserveMaintenance(service string, rows int, at time.Time)

ObserveMaintenance records a run of a leader service.

func (*Metrics) Queue

func (m *Metrics) Queue(q string) string

Queue caps a queue label value.

Jump to

Keyboard shortcuts

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