Documentation
¶
Overview ¶
Package sysstat reads the handful of machine-level numbers that both the web panel and the Telegram bot report on: processor, memory, swap, disk, load and uptime.
It exists because the panel imports the bot (it starts it), so the bot cannot import the panel back. Rather than sampling the same counters twice with two sets of rounding, both read them here — an alert that says 86% and a dashboard that says 85% for the same instant is a support question nobody should have to answer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CPUPercentOver ¶
LoadString formats the three load averages the way uptime(1) does. CPUPercentOver samples the processor across a real window.
Get's figure is the instantaneous one — cpu.Percent with a zero interval, which reports the delta since the last call in this process. In a long-lived process (the panel, the monitor) that is a sensible few seconds of history and costs nothing, which is why Get uses it.
In a process that exists to answer one question and exit it means nothing at all. `hashem node exec` is exactly that, and it is how a panel reads a managed server: there is no previous call, so the only delta available is the one since the package initialised microseconds earlier. Over a window that short /proc/stat has usually not ticked, and gopsutil's own arithmetic then returns 0 when nothing moved and 100 when a single jiffy landed. That is why a managed server's card jumped between 0%, 100% and 50% on every poll while the machine sat idle — the readings were not noisy, they were meaningless.
Sampling over a real window costs that window once per call, which is the price of a figure that means anything in a one-shot process.
func HumanBytes ¶
HumanBytes renders a byte count in the largest unit that keeps it readable.
func HumanDuration ¶
HumanDuration renders a duration as days/hours/minutes, dropping the units that would read as zero.
Types ¶
type Snapshot ¶
type Snapshot struct {
Hostname string
OS string
Uptime time.Duration
CPUPercent float64
CPUCores int
Load1 float64
Load5 float64
Load15 float64
MemUsed uint64
MemTotal uint64
MemPercent float64
SwapUsed uint64
SwapTotal uint64
SwapPercent float64
DiskUsed uint64
DiskTotal uint64
DiskPercent float64
}
Snapshot is one reading of the machine. Any field may be zero if the underlying counter could not be read; callers should treat zero as "unknown" rather than "idle".
func Get ¶
func Get() Snapshot
Get samples the machine now.
The processor figure is the instantaneous reading (cpu.Percent with a zero interval), which is what the panel has always shown. It is cheap enough to call on a short timer and does not block for a sampling window.