Documentation
¶
Overview ¶
Package uptime computes uptime and latency from heartbeats and the consensus status history, maintains the hourly and daily rollups, compacts old raw data and enforces retention (FA-UPT-01..06).
Uptime % = up / (total − maintenance − unknown) × 100. DEGRADED and PARTIAL count as up (FA-UPT-01). All computations are pure functions of the stored data, so every voter derives the same rollups (FA-UPT-03).
Index ¶
Constants ¶
const ( // CompactAfter is how long raw heartbeats are kept in full (FA-UPT-04). CompactAfter = 48 * time.Hour )
Variables ¶
var DefaultRetention = Retention{Raw: 30 * 24 * time.Hour, Hourly: 365 * 24 * time.Hour}
DefaultRetention follows Pflichtenheft 7.3.
Functions ¶
Types ¶
type Calculator ¶
Calculator computes buckets from the raw data.
func (*Calculator) Compute ¶
func (c *Calculator) Compute(ctx context.Context, m store.Monitor, start, end int64, opts ComputeOptions) ([]store.Rollup, error)
Compute returns the rollups of [start, end): the consensus view first (if opts.NodeID is ""), then one per node that reported, ordered by node ID. For the consensus alone without latency, heartbeats are not read.
type ComputeOptions ¶
type ComputeOptions struct {
BucketMs int64
// NodeID restricts the result to one node; "" includes the consensus.
NodeID string
// ConsensusOnly skips per-node rollups.
ConsensusOnly bool
// Latency reads heartbeats for latency even if only the consensus is needed.
Latency bool
}
ComputeOptions select what Compute returns.
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
Job maintains rollups, compaction and retention of metrics.db. It runs locally on every voter; the results are deterministic (FA-UPT-03).
type JobOptions ¶
type JobOptions struct {
State store.State
Metrics store.Metrics
// Vacuum returns freed pages of metrics.db to the file system.
Vacuum func(ctx context.Context) error
Logger *slog.Logger
// Compaction enables FA-UPT-04 (RAW_COMPACTION).
Compaction bool
Retention Retention
// Now returns the wall clock; tests replace it.
Now func() time.Time
// ReplicatedUntil returns the time up to which the heartbeats of all peers
// are replicated here (FA-REP-03). Hours after it are held back. Nil means
// no hold-back.
ReplicatedUntil func() time.Time
}
JobOptions configure a Job.
type Retention ¶
type Retention struct {
Raw time.Duration // heartbeats and latency minutes
Hourly time.Duration
Daily time.Duration
}
Retention configures how long data is kept (FA-UPT-05). Zero keeps forever.
type Service ¶
Service answers uptime queries from rollups and computes the buckets that are not rolled up yet from the raw data.
func (*Service) ConsensusTotals ¶
func (s *Service) ConsensusTotals(ctx context.Context, tenantID string, ms []store.Monitor, r Range, now time.Time) (map[string]store.Rollup, error)
ConsensusTotals returns the consensus total of range r for each monitor of the tenant. For every monitor the total equals Stats(ctx, m, "", r, now, false).Total: the same hour selection and the same calculation, but the rollups and the status history of all monitors are loaded with one query each (NFA-PERF-03). Only hourly ranges are supported, and every monitor must belong to tenantID.
func (*Service) Stats ¶
func (s *Service) Stats(ctx context.Context, m store.Monitor, nodeID string, r Range, now time.Time, latency bool) (Stats, error)
Stats returns the uptime of m over r, for one node or the consensus (nodeID ""). Without latency, consensus buckets are computed from the status history alone, which keeps monitor lists fast (NFA-PERF-03).