hostcapacity

package
v0.8.4 Latest Latest
Warning

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

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

Documentation

Overview

Package hostcapacity refuses new runs while the host is short of memory or over a load ceiling, so a burst of launches cannot push the machine that hosts the daemon (and everything else on it) into swap or an OOM kill.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadProc

func ReadProc() (availMiB int, load1 float64, err error)

ReadProc reads MemAvailable from /proc/meminfo and the 1-minute load average from /proc/loadavg. In a container or a kind node these describe the kernel the daemon runs on (on WSL2, the whole VM), not a cgroup's share of it.

Types

type ErrRefused

type ErrRefused struct{ Reason string }

ErrRefused is returned by Admit when the host is over a limit. Reason names the measured value and the limit it crossed, e.g. "load1=112.40 > 100".

func (ErrRefused) Error

func (e ErrRefused) Error() string

type Guard

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

Guard checks the host against Limits. A nil *Guard admits everything.

func New

func New(limits Limits, read func() (availMiB int, load1 float64, err error)) *Guard

New returns a Guard over limits that measures the host with read; the daemon passes ReadProc.

func (*Guard) Admit

func (g *Guard) Admit() error

Admit returns nil when the guard is disabled or the host is within limits, else an ErrRefused naming every limit crossed.

type Limits

type Limits struct {
	MinAvailableMiB int // refuse while MemAvailable is below this many MiB
	MaxLoad1        int // refuse while the 1-minute load average is above this
}

Limits are the admission thresholds. A zero field disables that check, and the zero value disables the guard entirely.

Jump to

Keyboard shortcuts

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