Documentation
¶
Overview ¶
Package hostpressure watches CPU and memory pressure on the host and tells the build path to wait or slow down before the kernel starts killing processes.
Index ¶
Constants ¶
const WaitMessage = "waiting: host under memory pressure"
WaitMessage is the status shown while a new build waits for the host to recover.
Variables ¶
var ErrUnsupported = errors.New("hostpressure: no memory source on this host")
ErrUnsupported means the host exposes no memory source to read.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Enabled bool
ShedEnabled bool
CPUWarn, CPUCritical float64 // cpu some avg10
MemWarn, MemCritical float64 // memory some avg10
MemFullWarn, MemFullCritical float64 // memory full avg10
AvailWarn, AvailCritical float64 // MemAvailable as percent of total, lower is worse
LoadWarn, LoadCritical float64 // used only without PSI
// ExitPercent scales every enter threshold to its exit threshold so a state leaves only after it clearly eased.
ExitPercent float64
Hold time.Duration
Jitter time.Duration
Interval time.Duration
NoSwapRAM int64 // bytes: flag missing swap below this much RAM
}
Config holds the live thresholds. Percent fields are 0 to 100, load is load1 per CPU times 100.
type ConsumerFunc ¶
ConsumerFunc lists the biggest memory users; it must be bounded.
type Guard ¶
type Guard struct {
// OnChange runs after the state changes, outside the lock.
OnChange func(Status)
// Sink receives every evaluation, for gauges.
Sink func(Status)
// contains filtered or unexported fields
}
Guard evaluates samples with hysteresis and gates new builds.
func (*Guard) Admit ¶
Admit blocks a new build while the host is critical, calls wait once with WaitMessage, then resumes after a random jitter. It fails only when ctx ends and never touches work that is already running.
func (*Guard) BuildCap ¶
BuildCap lowers a build concurrency limit to 1 while the host is warm or worse; 0 (unlimited) is capped too.
func (*Guard) Observe ¶
Observe takes one reading and applies it. Escalation is immediate; stepping down needs Hold below the exit thresholds.
func (*Guard) SetConsumers ¶
func (g *Guard) SetConsumers(f ConsumerFunc)
SetConsumers wires the top consumer lookup run on each escalation.
type ProcReader ¶
ProcReader reads a /proc shaped tree rooted at Root ("/proc" when empty).
type Sample ¶
type Sample struct {
PSI bool `json:"psi"`
CPUSome10 float64 `json:"cpu_some_avg10"`
CPUSome60 float64 `json:"cpu_some_avg60"`
MemSome10 float64 `json:"mem_some_avg10"`
MemSome60 float64 `json:"mem_some_avg60"`
MemFull10 float64 `json:"mem_full_avg10"`
MemFull60 float64 `json:"mem_full_avg60"`
MemTotal int64 `json:"mem_total_bytes"`
MemAvailable int64 `json:"mem_available_bytes"`
SwapTotal int64 `json:"swap_total_bytes"`
SwapFree int64 `json:"swap_free_bytes"`
NumCPU int `json:"num_cpu"`
Load1 float64 `json:"load1"`
}
Sample is one reading. PSI is false where /proc/pressure is missing (old kernels, containers, other systems).
type Status ¶
type Status struct {
State State `json:"state"`
Since time.Time `json:"since"`
Source string `json:"source"` // psi, fallback or unavailable
Reasons []string `json:"reasons"`
Sample Sample `json:"sample"`
TopConsumers []Consumer `json:"top_consumers"`
Actions []string `json:"actions"`
NoSwap bool `json:"no_swap"`
}
Status is the last evaluation.