Documentation
¶
Overview ¶
Package sysinfo reads the kernel's own counters: /proc/stat for CPU time, /proc/meminfo for memory, and statfs for storage. The pure-Go counterpart of crates/wayle-sysinfo's read path.
Index ¶
- Variables
- func AutoBytes(bytes uint64) string
- func CPUTemperature(sensor string) (float32, bool)
- func CoreFrequencyMHz(core int) uint64
- func GiB(bytes uint64) string
- func ReadNetDevTotals(path string) (map[string]NetTotals, error)
- func ReadNetTotals() (map[string]NetTotals, error)
- func SelectInterface(totals map[string]NetTotals, iface string) (string, bool)
- func Usage(prev, cur CPUTimes) float32
- type CPU
- type CPUReader
- type CPUStat
- type CPUTimes
- type Core
- type Disk
- type Memory
- type NetTotals
- type Rate
- type Sensor
- type Storage
Constants ¶
This section is empty.
Variables ¶
var ( ProcRoot = "/proc" SysRoot = "/sys" )
ProcRoot and SysRoot are the procfs and sysfs mounts; tests repoint them at fake trees.
var SysClassNet = "/sys/class/net"
SysClassNet is the interface directory; tests repoint it.
Functions ¶
func AutoBytes ¶
AutoBytes is bytesize 2's Display: IEC (1024-based) units with one decimal, "KiB" through "EiB", plain bytes below a kibibyte. The unit is picked from ln(size)/ln(1024), as its std build does.
func CPUTemperature ¶
CPUTemperature is find_cpu_temperature: a named sensor by label substring (case-insensitive), or for "auto" the first sensor matching each pattern in turn.
func CoreFrequencyMHz ¶
CoreFrequencyMHz is get_cpu_frequency: the core's cpufreq scaling_cur_freq (kHz), else the first MHz line of /proc/cpuinfo, else 0.
func ReadNetDevTotals ¶
ReadNetDevTotals is an alternative reader over /proc/net/dev used by the tests to drive counter snapshots; production reads sysfs.
func ReadNetTotals ¶
ReadNetTotals reads rx/tx byte totals per interface.
func SelectInterface ¶
SelectInterface is netstat's helpers.rs select_interface: "auto" picks the busiest non-loopback interface, anything else matches by exact name (ok=false when absent).
Types ¶
type CPU ¶
type CPU struct {
UsagePercent float32
AvgFrequencyMHz uint64
MaxFrequencyMHz uint64
BusiestCoreFreqMHz uint64
// TemperatureC is the matched sensor's reading; ok is false
// without one.
TemperatureC float32
HasTemperature bool
Cores []Core
}
CPU is polling/cpu.rs's CpuData.
type CPUReader ¶
type CPUReader struct {
// Sensor is the temp-sensor key: "auto" or a label substring.
Sensor string
// contains filtered or unexported fields
}
CPUReader keeps the previous counters between polls, as the Rust poll loop keeps its System.
type CPUTimes ¶
type CPUTimes struct {
Work, Total uint64
}
CPUTimes is one /proc/stat cpu line reduced the way the sysinfo crate does: work is user, nice, system, irq, and softirq (with guest time taken out of user and nice, where the kernel already counts it); total adds idle, iowait, steal, and the guest time back.
type Disk ¶
type Disk struct {
MountPoint string
Filesystem string
TotalBytes uint64
AvailableBytes uint64
UsedBytes uint64
}
Disk is one mounted filesystem from the sysinfo crate's disk list.
type Memory ¶
Memory is one /proc/meminfo snapshot, in bytes.
func (Memory) SwapPercent ¶
SwapPercent maps swap usage onto 0..100.
func (Memory) UsagePercent ¶
UsagePercent maps used onto 0..100.
type Sensor ¶
Sensor is one hwmon temperature input, labeled the way the sysinfo crate labels its components.