sysstat

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

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

func CPUPercentOver(d time.Duration) float64

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

func HumanBytes(b uint64) string

HumanBytes renders a byte count in the largest unit that keeps it readable.

func HumanDuration

func HumanDuration(d time.Duration) string

HumanDuration renders a duration as days/hours/minutes, dropping the units that would read as zero.

func Round1

func Round1(f float64) float64

Round1 rounds to one decimal place, so a reading never renders as 84.99999.

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.

func (Snapshot) LoadString

func (s Snapshot) LoadString() string

Jump to

Keyboard shortcuts

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