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, people online that varied by at least MinPeopleSpread, and a CPU that follows them (R² of at least MinFitR2). Otherwise Fit says why. The headroom it gives is held to MaxHeadroomOverPeak times the people the node has ever carried: a line is not trusted far beyond the data it was drawn from.
- Only hours that say something about people's load count: an hour with fewer than MinHourFill of the node's fullest hour's samples (an install, a reconnect, the hour that is still running) and the node's first hour (Node.FirstHour: the install is not people) are left out of every number. A node whose history is shorter than MinFitHours hours is "unknown" and gets no advice about people: the first day is not a pattern.
- One burst is not a load. The CPU and the link are both judged by the busy hour's mean and by the typical hourly peak (p75), so a single spike in a week changes neither the status nor the advice; the highest peak is shown beside them.
Index ¶
Constants ¶
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 // The link: the typical (p75) hourly peak of the busier direction against it, and the busiest hour's mean. A saturated link // is minutes of full pipe inside the hour, so the mean's scale is lower, like the CPU's. The single highest peak is shown, // never judged: a speed measurement or a download of a few seconds fills any link. LinkBusyPct = 70.0 LinkOverPct = 90.0 LinkHourBusyPct = 60.0 LinkHourOverPct = 80.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 // MaxHeadroomOverPeak holds the headroom to this many times the people the node has carried at once (at least // MinPeopleBasis of them): the per-person cost was read between none and that peak, and nothing says it stays the same far // beyond it. MaxHeadroomOverPeak = 5 MinPeopleBasis = 10 // 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 // MinFitR2 is how much of the hourly CPU the people must explain: below it the slope is noise, and a noise slope makes // room for thousands. MinFitR2 = 0.2 // MinHourFill is the share of the node's fullest hour's samples an hour needs to count. MinHourFill = 0.5 // MinPeopleToMove is the people online in the busy hour from which moving some of them is advice: a node that is busy with // one or two people online is busy with something else. MinPeopleToMove = 3.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.
const ( StatusOK = "ok" StatusBusy = "busy" StatusOverloaded = "overloaded" StatusUnknown = "unknown" // no hour with samples in the window )
Statuses.
const ( ResCPU = "cpu" ResSteal = "steal" ResBandwidth = "bandwidth" ResRAM = "ram" ResConntrack = "conntrack" ResDisk = "disk" )
Resources a node can run out of (Report.Bottleneck).
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).
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 RecCPUBusyFewPeople = "cpu_busy_few_people" // cpu_pct, people: busy with hardly anyone online, so not people's load RecBandwidthLimitLow = "bandwidth_limit_low" // link_mbps (the owner's), seen_mbps: the node carried more than the number set; check it RecBandwidthBusy = "bandwidth_busy" // peak_pct (typical), hour_pct (busiest hour), 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.
const ( SevInfo = "info" SevWarn = "warn" SevCrit = "crit" )
Severities of a recommendation.
Variables ¶
This section is empty.
Functions ¶
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
// FirstHour is the start of the node's first hour of host load ever stored (0 = not known: then nothing is taken for the
// first hour). Its readings are the install and are left out; a node whose history is under MinFitHours hours is "unknown".
FirstHour int64
// MeasuredMbps is the fastest a stored speed test between this node and another (kept 7 days) went, Mbit/s; 0 = none. It
// proves the link is at least that wide.
MeasuredMbps uint32
// WindowHours is the window the hours were read for (0 = not known). A day-long window holds fewer than MinFitHours settled
// hours (the hour still running does not count), so it asks for that many fewer.
WindowHours int
// SpeedTests is when the node's own speed measurements ended (unix seconds). The traffic peak of the hours they ran in
// is not people's traffic and is left out of the link reading.
SpeedTests []int64
}
Node is what the report reads about one node.
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 counts every hour with samples; the numbers below are read from the settled ones (see the package comment).
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
// The highest hourly peaks of the main NIC (a single burst may be all they are), not counting hours of a speed measurement.
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 is the highest hourly peak against the link (shown only); BandwidthTypicalPct the p75 of the hourly
// peaks and BandwidthBusyHourPct the highest hourly mean: what the status and the advice read.
BandwidthPeakPct, BandwidthTypicalPct, BandwidthBusyHourPct *float64
// LinkSeenMbps is set when the owner's capacity (LinkSource "configured") is below what the node was seen to carry: a
// stored speed test or an hourly peak went faster. The number set is then wrong, the shares above are against it, and the
// link is judged busy at most, with bandwidth_limit_low in place of bandwidth_busy. 0 = not the case.
LinkSeenMbps uint32
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.
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.