Documentation
¶
Overview ¶
Package sysinfo provides cross-platform system statistics collection for CPU, memory, disk, load average, GPU, and network throughput.
All collection functions return an Available flag. When a stat cannot be collected (wrong platform, missing /proc, no GPU), Available is false and the caller should skip it silently.
Index ¶
- func Format(stats Stats, format string, show []string) string
- func FormatBytes(bytes uint64) string
- func FormatBytesPerSec(bps float64) string
- func FormatLoadavg(l LoadStat) string
- func GPUAvailable() bool
- func ParseNetDev(content string) (rxTotal, txTotal uint64)
- func ParseProcStat(content string) (uint64, uint64, error)
- type CPUStat
- type Collector
- type DiskStat
- type GPUStat
- type LoadStat
- type MemStat
- type NetworkStat
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format renders stats as a string for the tmux status bar. format: "compact" (icons+values), "full" (labels+values), "minimal" (values only) show: which stats to include (e.g., ["cpu", "ram", "disk"])
func FormatBytes ¶
FormatBytes formats a byte count for human-readable display.
func FormatBytesPerSec ¶
FormatBytesPerSec formats bytes/sec for display.
func FormatLoadavg ¶
FormatLoadavg formats load averages for display.
func GPUAvailable ¶
func GPUAvailable() bool
GPUAvailable returns whether a GPU monitoring tool was detected.
func ParseNetDev ¶
ParseNetDev parses /proc/net/dev and returns total rx/tx bytes across all non-loopback interfaces. Exported for testing.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector runs a background goroutine that periodically collects system stats and caches them for consumption by all tmux sessions.
func NewCollector ¶
NewCollector creates a new stats collector. Call Start() to begin collection. onUpdate is called after each collection cycle (e.g., to refresh tmux status bars).
type DiskStat ¶
type DiskStat struct {
Available bool
UsedBytes uint64
TotalBytes uint64
UsagePercent float64 // 0-100
}
DiskStat represents root filesystem disk usage.
type GPUStat ¶
type GPUStat struct {
Available bool
UsagePercent float64 // 0-100
Name string // e.g., "NVIDIA GeForce RTX 3090"
}
GPUStat represents GPU utilization (best-effort).
type LoadStat ¶
LoadStat represents system load averages.
func ParseLoadavg ¶
ParseLoadavg parses /proc/loadavg content. Exported for testing. Format: "0.50 0.35 0.30 1/234 5678"
type MemStat ¶
type MemStat struct {
Available bool
UsedBytes uint64
TotalBytes uint64
UsagePercent float64 // 0-100
}
MemStat represents memory usage.
func ParseMeminfo ¶
ParseMeminfo parses /proc/meminfo content. Exported for testing.
type NetworkStat ¶
NetworkStat represents network throughput calculated from counter deltas.