diskhistory

package
v0.9.2 Latest Latest
Warning

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

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

Documentation

Overview

Package diskhistory keeps a small time series of data dir free space and per-category Docker bytes, and forecasts when the disk fills.

Index

Constants

View Source
const (
	DefaultWindowDays = 30
	DefaultMinDays    = 7
)

Defaults from the storage page spec: fit the last 30 days, and stay hidden until a week of data exists so the number is never a guess.

Variables

This section is empty.

Functions

func BasisDays

func BasisDays(samples []Sample) int

BasisDays counts the distinct UTC days that have a sample.

Types

type Categories

type Categories struct {
	Images, Containers, Volumes, BuildCache int64
}

Categories are the per-category byte totals taken from the Docker usage cache.

type Result

type Result struct {
	DaysUntilFull float64
	BasisDays     int
}

Result is a days-until-full estimate and how many days of data it rests on.

func Forecast

func Forecast(samples []Sample) *Result

Forecast fits used bytes over the last DefaultWindowDays with least squares. It returns nil when under DefaultMinDays of data exists or usage is not growing.

func ForecastWith

func ForecastWith(samples []Sample, windowDays, minDays int) *Result

ForecastWith is Forecast with explicit window and minimum day counts.

type Sample

type Sample struct {
	At              time.Time `json:"at"`
	FreeBytes       int64     `json:"free_bytes"`
	TotalBytes      int64     `json:"total_bytes"`
	ImagesBytes     int64     `json:"images_bytes"`
	ContainersBytes int64     `json:"containers_bytes"`
	VolumesBytes    int64     `json:"volumes_bytes"`
	BuildCacheBytes int64     `json:"build_cache_bytes"`
}

Sample is one recorded moment. Category fields are 0 when Docker usage was unavailable.

type Sampler

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

Sampler records one sample per interval, plus one at boot when the last is stale.

func NewSampler

func NewSampler(store *Store, src Source, settings Settings, poll time.Duration, logger *slog.Logger) *Sampler

NewSampler builds a sampler. poll is how often it re-checks the interval and prunes.

func (*Sampler) Run

func (s *Sampler) Run(ctx context.Context)

Run ticks at boot and then every poll until ctx ends.

func (*Sampler) Tick

func (s *Sampler) Tick(ctx context.Context) error

Tick records a sample when none exists within the interval, then prunes past retention.

type Settings

type Settings struct {
	Interval  func() time.Duration
	Retention func() time.Duration
}

Settings reads the live tunables on every tick so a saved change applies without a restart.

type Source

type Source struct {
	Stat  func() (free, total int64, err error)
	Usage func(ctx context.Context) (Categories, error)
}

Source supplies live readings. Usage may be nil or fail; Stat is required.

type Store

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

Store persists samples in the control plane database.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore wraps the shared database handle.

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, sm Sample) error

Insert records one sample; a repeat of the same instant replaces the earlier row.

func (*Store) Latest

func (s *Store) Latest(ctx context.Context) (time.Time, error)

Latest returns the newest sample time, or the zero time when none exist.

func (*Store) Prune

func (s *Store) Prune(ctx context.Context, cutoff time.Time) (int64, error)

Prune deletes samples older than cutoff and returns how many went.

func (*Store) Since

func (s *Store) Since(ctx context.Context, since time.Time) ([]Sample, error)

Since returns samples at or after since, oldest first.

Jump to

Keyboard shortcuts

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