Documentation
¶
Overview ¶
Package cache implements the collect-on-an-interval / serve-from-cache model: a background scheduler gathers metrics every interval into an atomically-swapped snapshot, and the HTTP handler serves that snapshot. Hardware is therefore never read on a scrape — only on a tick.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache holds the latest Snapshot for lock-free reads.
func (*Cache) Gather ¶
Gather serves the cached families plus freshly-computed staleness meta-metrics (age is computed at call time, so it stays truthful between ticks). It never triggers a collection. Satisfies prometheus.GathererFunc when wrapped.
type Gatherer ¶
type Gatherer interface {
Gather() ([]*dto.MetricFamily, error)
}
Gatherer is the subset of prometheus.Gatherer the cache needs. Declared here at the point of consumption; a *prometheus.Registry satisfies it.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler gathers from src into a Cache on an interval.
func NewScheduler ¶
NewScheduler wires a scheduler. now is injected for testability.
func (*Scheduler) CollectOnce ¶
CollectOnce gathers once and stores the snapshot. A gather error is logged but any partial families returned are still stored. Returns the gather error (used by the eager startup collection to surface problems).