Documentation
¶
Overview ¶
Package sampler reads the load of the host it runs on: CPU per core, memory, network rates and the process list. It is pure Go without cgo: libSystem through purego on macOS, /proc on Linux, kernel32, ntdll and iphlpapi on Windows. It knows nothing about windows or charts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("sampler: this OS is not supported")
ErrUnsupported is returned by New on an OS without a source.
Functions ¶
This section is empty.
Types ¶
type Host ¶
type Host struct {
Name string
OS string // "macOS 26.0", "Windows 11 (build 26100)", the distribution on Linux
CPU string // brand string, empty where the OS has none
Cores int // logical cores
Memory uint64 // bytes of RAM
}
Host is what does not change while the program runs.
type Memory ¶
type Memory struct {
Total, Used, App, Wired, Compressed, Cached, Free uint64
SwapTotal, SwapUsed uint64
}
Memory is in bytes. Used is Total minus what the system can hand out at once. App, Wired and Compressed split Used where the OS tells (macOS); Cached is file cache that can be dropped.
type Process ¶
Process is one row of the process list. CPU is percent of one core, so it passes 100 for a process that runs on several.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler turns the counters of a source into rates.
type Snapshot ¶
type Snapshot struct {
Time time.Time
CPU float64 // 0..1, all cores
User float64 // share of CPU in user code, 0..1 of all cores
System float64 // share in the kernel
Cores []float64 // 0..1 each
Load [3]float64
HasLoad bool
Uptime time.Duration
Mem Memory
// RxRate and TxRate are bytes per second over all non-loopback interfaces that are up.
RxRate, TxRate float64
Procs []Process // nil when this sample did not read them
}
Snapshot is one reading. Rates (CPU, RxRate, TxRate) are over the time since the previous Sample and are zero in the first one.