forecast

package
v0.2.0-beta.18 Latest Latest
Warning

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

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

Documentation

Overview

Package forecast projects a resource's usage trend forward with a plain ordinary-least-squares line fit over recent (timestamp, bytes used) samples: deterministic, pure-Go, no external model, the same read-and-suggest shape internal/rightsizing already establishes. Real usage rarely grows in a straight line, so the result is a rough heads-up, never a guarantee, and every caller surfacing it must say so.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Point

type Point struct {
	Timestamp time.Time
	UsedBytes float64
}

Point is one (timestamp, bytes used) observation. Timestamps need not be sorted or evenly spaced; Project sorts its own copy.

type Projection

type Projection struct {
	// SlopeBytesPerDay is the fitted line's slope: always > 0, since
	// Project returns nil otherwise.
	SlopeBytesPerDay float64
	// DaysUntilFull is how many days from now the fitted line crosses
	// TotalBytes, floored at 0 (never negative, even if the line has
	// already crossed).
	DaysUntilFull float64
	// FullAt is now plus DaysUntilFull, the projected exhaustion
	// timestamp.
	FullAt time.Time
	// CurrentUsedBytes is the fitted line's value at now, not the raw
	// last sample, so a single noisy spike doesn't move the headline
	// number.
	CurrentUsedBytes float64
	TotalBytes       float64
	SampleCount      int
	// Span is the time between the earliest and latest sample Project
	// fit the line over.
	Span time.Duration
}

Projection is Project's result for one resource: a real, growing trend with a projected exhaustion point. Project returns nil instead of a Projection when the trend is flat, improving, or under-sampled, so a nil result always means "nothing to warn about," never "zero days left."

func Project

func Project(points []Point, totalBytes float64, now time.Time) *Projection

Project fits an ordinary-least-squares line through points and projects it forward to totalBytes. Returns nil when there isn't enough history (fewer than minPoints samples, or less than minSpan between the earliest and latest), when totalBytes isn't a real capacity figure (<= 0), or when the fitted slope is zero or negative: an operator should never be warned about a trend that isn't actually pointing at exhaustion, even if the raw samples are noisy around a flat average.

Jump to

Keyboard shortcuts

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