capacity

package
v0.1.90-dev.5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package capacity reads a node's hours of host load (store.HostHour) as an answer to "how loaded is it, what runs out first, and how many more people can it take". It is pure: no store, no clock, no I/O, so every number it gives is tested on fixed input. The OpsService (GetFleetLoad), the MCP tool capacity_report and the admin's Load view read it.

Rules it keeps:

  • "Not known" is never zero. An hour whose samples came from an agent that predates the resource fields (ExtSamples == 0) says nothing about steal, swap, conntrack or the agent itself; those values are nil when no hour of the window knows them, and the report asks for an agent update.
  • Every float it returns is finite: a division by a zero count, a fit over flat data or a bogus row gives nil (or 0 where 0 is the truth), never NaN or Inf.
  • The per-person costs come from a least-squares fit over the hours, and only when the hours can carry one: at least MinFitHours hours with samples and people online that varied by at least MinPeopleSpread. Otherwise Fit says why.

Index

Constants

View Source
const (
	CPUBusyPct = 60.0 // busy-hour CPU mean
	CPUOverPct = 80.0
	// The hourly CPU peaks are judged by their 75th percentile, the peak most hours stay under: a server's own upkeep (the
	// distribution's updates, a restart) spikes a small box to 100% for a moment in a few hours a day, and the 95th percentile
	// read that as an overloaded node at a 10% busy hour. Peaks alone make a node busy at most: what people feel is the mean.
	CPUPeakBusyPct   = 85.0 // p75 of the hourly CPU peaks
	CPUPeakOverPct   = 97.0 // the pressure scale of the peaks (never "overloaded" by itself)
	StealBusyPct     = 10.0 // p95 of the hourly steal means (doctor cpu_steal: 10 / 25 over 10 minutes)
	StealOverPct     = 25.0
	LinkBusyPct      = 70.0 // the busier direction's hourly peak against the link
	LinkOverPct      = 90.0
	RAMBusyPct       = 85.0 // hourly peak of used memory (MemTotal - MemAvailable)
	RAMOverPct       = 95.0
	ConntrackBusyPct = 80.0 // doctor conntrack_fill: 80 / 95
	ConntrackOverPct = 95.0
	DiskBusyPct      = 80.0 // doctor disk_space: 80 / 92
	DiskOverPct      = 92.0

	// HeadroomCPUPct is where the busy hour may go: the headroom is the people a node can add before its busy-hour CPU
	// mean reaches it.
	HeadroomCPUPct = CPUOverPct
	// MaxHeadroom caps a headroom that a tiny per-person cost would make absurd.
	MaxHeadroom = 10000

	// MinFitHours and MinPeopleSpread gate the per-person fit: a day of hours, and people online that moved enough for
	// the CPU to follow them.
	MinFitHours     = 24
	MinPeopleSpread = 4.0

	// SwapNoteBytes is the swap use worth a note: a few idle pages swapped out are normal.
	SwapNoteBytes = 100 << 20

	// The agent's memory: a leak shows as the daily peak climbing for days, steadily, faster than the people do.
	LeakMinDays      = 3
	LeakMinPctPerDay = 5.0
	LeakMinR2        = 0.6
)

Thresholds. "Busy" is worth a look; "overloaded" is what people already feel. The CPU ones are hourly: a busy hour at a 60% mean has minutes at the ceiling inside it. The others match the node doctor's, so the Load view and the doctor's alerts do not disagree.

View Source
const (
	StatusOK         = "ok"
	StatusBusy       = "busy"
	StatusOverloaded = "overloaded"
	StatusUnknown    = "unknown" // no hour with samples in the window
)

Statuses.

View Source
const (
	ResCPU       = "cpu"
	ResSteal     = "steal"
	ResBandwidth = "bandwidth"
	ResRAM       = "ram"
	ResConntrack = "conntrack"
	ResDisk      = "disk"
)

Resources a node can run out of (Report.Bottleneck).

View Source
const (
	FitOK       = "ok"
	FitFewHours = "few_hours" // fewer than MinFitHours hours with samples
	FitFlat     = "flat"      // people online barely changed (an idle node among them)
	FitNoTrend  = "no_trend"  // the CPU does not rise with the people
)

Fit outcomes (Report.Fit).

View Source
const (
	RecUpdateAgent        = "update_agent"         // the agent predates the resource fields: steal, swap, conntrack and its own cost are not known
	RecStealHigh          = "steal_high"           // steal_pct: the provider oversells the host; move the node
	RecConntrackNearLimit = "conntrack_near_limit" // fill_pct, limit: raise nf_conntrack_max or spread people
	RecCPUBusy            = "cpu_busy"             // cpu_pct, target, target_headroom: move people to the node with the most headroom
	RecCPUBusyAddNode     = "cpu_busy_add_node"    // cpu_pct: no other node has room; add one
	RecBandwidthBusy      = "bandwidth_busy"       // peak_pct, link_mbps, target (optional)
	RecRAMHigh            = "ram_high"             // ram_pct
	RecSwapInUse          = "swap_in_use"          // swap_mb
	RecDiskFilling        = "disk_filling"         // disk_pct
	RecAgentMemoryGrowing = "agent_memory_growing" // growth_pct_day, rss_mb, days
)

Recommendation codes. Params are plain decimal strings and node names; the UI and the assistant word them.

View Source
const (
	SevInfo = "info"
	SevWarn = "warn"
	SevCrit = "crit"
)

Severities of a recommendation.

Variables

This section is empty.

Functions

func Fleet

func Fleet(nodes []Node) ([]Report, Summary)

Fleet reads every node and the fleet as a whole. Reports are ordered most pressing first (overloaded, busy, ok, unknown; then by pressure, then by name).

Types

type Node

type Node struct {
	ID, Name string
	// CPUs and RAMTotal are the node's facts (0 = not known; the hours carry their own RAM total too).
	CPUs     uint32
	RAMTotal uint64
	// BandwidthMbps is the owner's capacity of the node (Node.bandwidth_mbps); 0 falls back to the NIC's link speed.
	BandwidthMbps uint32
	// DiskUsed and DiskTotal are the latest sample's root file system (DiskTotal 0 = not known).
	DiskUsed, DiskTotal uint64
	Connected           bool
	// Hours of host load in the window, any order.
	Hours []store.HostHour
}

Node is what the report reads about one node.

type Rec

type Rec struct {
	Code     string
	Severity string
	Params   map[string]string
}

Rec is one recommendation.

type Ref

type Ref struct {
	ID, Name    string
	BusyHourCPU float64
	Headroom    *int
	Status      string
}

Ref names a node in the summary.

type Report

type Report struct {
	ID, Name  string
	CPUs      uint32
	Connected bool
	Status    string
	// Bottleneck is the resource closest to its limit, when one is at least halfway there; "" otherwise.
	Bottleneck string
	// Pressure is how close the bottleneck is to its "overloaded" threshold, 1 = at it. It orders nodes.
	Pressure float64

	HoursWithData, ExtHours int
	// The busy hour: the hour with the highest CPU mean, and the people online in it.
	BusyHourUnix   int64
	BusyHourCPU    float64
	PeopleBusyHour float64
	PeoplePeak     uint32
	CPUPeakP95     float64 // the highest peaks, shown; a few spikes push it to 100
	CPUPeakTypical float64 // p75 of the hourly peaks: what the status and the advice read

	StealP95         *float64
	ConntrackPeakPct *float64
	ConntrackLimit   uint64
	RAMPeakPct       *float64
	SwapUsedMax      *uint64
	DiskUsedPct      *float64

	RxPeakBps, TxPeakBps uint64
	// LinkMbps is the capacity the traffic is set against; LinkSource "configured" (the owner's), "nic" (the link speed the
	// agent reported) or "" (not known).
	LinkMbps         uint32
	LinkSource       string
	BandwidthPeakPct *float64

	AgentCPUAvg, AgentCPUMax  *float64
	AgentRSSMax               *uint64
	AgentRSSGrowthPctPerDay   *float64
	AgentRSSDays              int
	AgentRSSGrowthConsistentR float64 // R² of the daily-peak fit (0 when there is none)

	// Fit says whether the per-person costs could be read (FitOK) or why not.
	Fit           string
	CPUPer100     *float64 // CPU percent of the machine per 100 people online
	CPUFitR2      *float64
	MbpsPerPerson *float64
	// Headroom is the people the node could add before its busy-hour CPU reaches HeadroomCPUPct (and, with a known link
	// and per-person traffic, before the busy direction reaches LinkOverPct). 0 when the node is overloaded already.
	Headroom *int

	Recs []Rec
}

Report is one node's capacity read. Pointers are nil when the value is not known.

func Read

func Read(n Node) Report

Read is one node's report, without the fleet's targets (Fleet adds them to cpu_busy and bandwidth_busy).

type Summary

type Summary struct {
	OK, Busy, Overloaded, Unknown int
	// HeadroomPeople adds up the nodes whose headroom is known (HeadroomNodes of them).
	HeadroomPeople, HeadroomNodes int
	// MostLoaded are up to three nodes closest to a limit, most loaded first; MostFree up to three that are not busy, most
	// headroom first.
	MostLoaded, MostFree []Ref
}

Summary is the fleet in a few numbers.

Jump to

Keyboard shortcuts

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