Documentation
¶
Overview ¶
Package resource implements per-process and system-wide resource sampling and enforcement.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
ProcessID string
Kind string // "rss" | "cpu"
Current float64
Limit float64
ExceedAction cliwrap.ExceedAction
}
Action describes an enforcement decision.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator tracks per-process limit breaches and fires actions.
func NewEvaluator ¶
func NewEvaluator(opts EvaluatorOptions) *Evaluator
NewEvaluator returns an Evaluator.
func (*Evaluator) RegisterLimits ¶
func (e *Evaluator) RegisterLimits(id string, l cliwrap.ResourceLimits)
RegisterLimits associates limits with a process ID.
func (*Evaluator) Unregister ¶
Unregister removes a process ID.
type EvaluatorOptions ¶
type EvaluatorOptions struct {
// OnAction is invoked (synchronously) when a sustained breach is detected.
OnAction func(Action)
// RSSBreachThreshold sets the consecutive breach count for memory.
// Default 3.
RSSBreachThreshold int
// CPUBreachThreshold sets the consecutive breach count for CPU.
// Default 10 (CPU samples are noisier).
CPUBreachThreshold int
}
EvaluatorOptions parameterises NewEvaluator.
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor periodically polls every child process in its Source.
type MonitorOptions ¶
type MonitorOptions struct {
Interval time.Duration
Source PIDSource
ProcessCollector ProcessCollector
SystemCollector SystemCollector
OnSample func(id string, s Sample)
OnSystem func(s SystemSample)
}
MonitorOptions configures a Monitor.
type PIDSource ¶
PIDSource is any object that can report the current set of (id, PID) pairs that should be sampled.
type ProcessCollector ¶
ProcessCollector returns a Sample for the given PID.
func DefaultProcessCollector ¶
func DefaultProcessCollector() ProcessCollector
DefaultProcessCollector returns the platform's default process collector.
type Sample ¶
type Sample struct {
PID int
RSS uint64 // bytes
VMS uint64 // bytes
CPUPercent float64 // 0-100 normalized per core
NumThreads int
NumFDs int
SampledAt time.Time
}
Sample is one point-in-time reading for a single process.
type SystemCollector ¶
type SystemCollector interface {
Collect() (SystemSample, error)
}
SystemCollector returns a system-wide sample.
func DefaultSystemCollector ¶
func DefaultSystemCollector() SystemCollector
DefaultSystemCollector returns the platform's default system collector.
type SystemSample ¶
type SystemSample struct {
TotalMemory uint64
AvailableMemory uint64
LoadAvg1 float64
LoadAvg5 float64
NumCPU int
SampledAt time.Time
}
SystemSample is one host-wide reading.
func (SystemSample) AvailableRatio ¶
func (s SystemSample) AvailableRatio() float64
AvailableRatio returns AvailableMemory / TotalMemory, or 0 if TotalMemory is 0.