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, cpuinfo func() uint64) uint64
- func GiB(bytes uint64) string
- 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 MemoryReader
- type NetReader
- type NetTotals
- type Rate
- 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.
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. A sensor is an input that reads; of inputs sharing a label the first that reads is the sensor. Without any hwmon sensor, thermal_zone0 stands in, unlabeled.
func CoreFrequencyMHz ¶
CoreFrequencyMHz is get_cpu_frequency: the core's cpufreq scaling_cur_freq (kHz), else cpuinfo, the first MHz line of /proc/cpuinfo (cpuinfoMHz), else 0. Read passes one cpuinfo for all its cores, so a machine without cpufreq reads /proc/cpuinfo once per poll, not once per core.
func ReadNetTotals ¶
ReadNetTotals reads every interface's rx/tx byte totals once.
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
// OmitFrequency and OmitTemperature leave out what the caller does
// not show, which is most of a read's cost: a file per core and a
// query of the sensor.
OmitFrequency, OmitTemperature bool
// 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 MemoryReader ¶
type MemoryReader struct {
// contains filtered or unexported fields
}
MemoryReader polls the meminfo totals through a kept descriptor.
func (*MemoryReader) Close ¶
func (r *MemoryReader) Close()
Close releases the descriptor; a later Read opens it again.
func (*MemoryReader) Read ¶
func (r *MemoryReader) Read() (Memory, error)
Read parses the totals in place; a missing line is an error, not a zero.
type NetReader ¶
type NetReader struct {
// contains filtered or unexported fields
}
NetReader polls /proc/net/dev through a kept descriptor: one file however many interfaces there are, rather than two per interface in sysfs.