Documentation
¶
Overview ¶
Package nodecapacity judges a node's disk, inode, memory and swap headroom against warn and critical thresholds and groups cleanup candidates by safety class.
Index ¶
Constants ¶
const ( EnvDiskWarnFree = "APP_NODE_DISK_WARN_FREE_PCT" EnvDiskCritFree = "APP_NODE_DISK_CRIT_FREE_PCT" EnvInodeWarnFree = "APP_NODE_INODE_WARN_FREE_PCT" EnvInodeCritFree = "APP_NODE_INODE_CRIT_FREE_PCT" EnvMemWarnAvail = "APP_NODE_MEM_WARN_AVAIL_PCT" EnvMemCritAvail = "APP_NODE_MEM_CRIT_AVAIL_PCT" EnvSwapWarnUsed = "APP_NODE_SWAP_WARN_USED_PCT" //nolint:gosec // env var name, not a credential EnvSwapCritUsed = "APP_NODE_SWAP_CRIT_USED_PCT" )
Env names for the default thresholds, all percentages.
const ( MetricDisk = "disk" MetricInodes = "inodes" MetricMemory = "memory" MetricSwap = "swap" )
Metric names.
const ( ClassDanglingImages = "dangling_images" ClassBuildCache = "build_cache" ClassStoppedContainers = "stopped_containers" ClassRollbackImages = "rollback_images" ClassOrphanedVolumes = "orphaned_volumes" )
Cleanup classes.
Variables ¶
var SafeStages = []janitor.Stage{janitor.StageContainers, janitor.StageImages, janitor.StageBuildCache}
SafeStages are the only stages a guardrail cleanup ever runs: volumes and deploy attempts are excluded.
Functions ¶
This section is empty.
Types ¶
type Band ¶
Band is a warn and critical pair. Free-style metrics (disk, inodes, memory) trip when the free percentage falls to or below the value; swap trips when the used percentage rises to it.
type Class ¶
type Class struct {
Name string `json:"name"`
Deletable bool `json:"deletable"`
Bytes int64 `json:"bytes"`
Items []janitor.Item `json:"items"`
}
Class is one group of cleanup candidates. Deletable false means the items are shown only.
type ImageSource ¶
type ImageSource interface {
ListAllImages(ctx context.Context) ([]docker.ImageRecord, error)
}
ImageSource lists local images so tagged unused ones can be shown as kept.
type MetricStatus ¶
type MetricStatus struct {
Name string `json:"name"`
Level Level `json:"level"`
Percent float64 `json:"percent"`
// Free and Total are bytes, or counts for inodes.
Free uint64 `json:"free"`
Total uint64 `json:"total"`
}
MetricStatus is one metric's reading and verdict.
type Preview ¶
Preview is a cleanup grouped by class.
func BuildPreview ¶
BuildPreview runs a dry pass and groups the outcome. Nothing is removed.
type Result ¶
type Result struct {
Preview
FreedBytes int64 `json:"freed_bytes"`
Error string `json:"error,omitempty"`
}
Result is an executed cleanup.
type Sample ¶
type Sample struct {
DiskTotal, DiskFree uint64
InodesTotal, InodesFree uint64
MemTotal, MemAvail uint64
SwapTotal, SwapFree uint64
}
Sample is one reading of a node's host. A zero total means the value is unreadable.
type Status ¶
type Status struct {
Metrics []MetricStatus `json:"metrics"`
Thresholds Thresholds `json:"thresholds"`
Worst Level `json:"worst"`
// Reason names the worst metric in words, empty when everything is fine.
Reason string `json:"reason,omitempty"`
}
Status is a node's overall verdict.
func Evaluate ¶
func Evaluate(s Sample, t Thresholds) Status
Evaluate judges a sample against thresholds. Unreadable metrics are reported as unknown and never block.
type Thresholds ¶
type Thresholds struct {
Disk Band `json:"disk_free_pct"`
Inodes Band `json:"inodes_free_pct"`
Memory Band `json:"memory_available_pct"`
Swap Band `json:"swap_used_pct"`
}
Thresholds are the percentage bands for every watched metric.
func ThresholdsFromEnv ¶
func ThresholdsFromEnv(lookup func(string) (string, bool)) Thresholds
ThresholdsFromEnv reads the defaults, falling back on unset or invalid values.
func (Thresholds) Merge ¶
func (t Thresholds) Merge(g store.NodeGuardrails) Thresholds
Merge applies a node's saved overrides on top of the defaults.
func (Thresholds) Validate ¶
func (t Thresholds) Validate() bool
Validate rejects percentages outside 0..100 or a critical band looser than its warn band.