sysinfo

package
v1.9.30 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(stats Stats, format string, show []string) string

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

func FormatBytes(bytes uint64) string

FormatBytes formats a byte count for human-readable display.

func FormatBytesPerSec

func FormatBytesPerSec(bps float64) string

FormatBytesPerSec formats bytes/sec for display.

func FormatLoadavg

func FormatLoadavg(l LoadStat) string

FormatLoadavg formats load averages for display.

func GPUAvailable

func GPUAvailable() bool

GPUAvailable returns whether a GPU monitoring tool was detected.

func ParseNetDev

func ParseNetDev(content string) (rxTotal, txTotal uint64)

ParseNetDev parses /proc/net/dev and returns total rx/tx bytes across all non-loopback interfaces. Exported for testing.

func ParseProcStat

func ParseProcStat(content string) (uint64, uint64, error)

ParseProcStat parses a /proc/stat content string for testing. Returns (total, idle, error).

Types

type CPUStat

type CPUStat struct {
	Available    bool
	UsagePercent float64 // 0-100
}

CPUStat represents CPU usage as a percentage across all cores.

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

func NewCollector(intervalSeconds int, onUpdate func()) *Collector

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).

func (*Collector) Get

func (c *Collector) Get() Stats

Get returns the latest cached stats snapshot.

func (*Collector) Start

func (c *Collector) Start()

Start begins the background collection goroutine.

func (*Collector) Stop

func (c *Collector) Stop()

Stop terminates the background collection goroutine.

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

type LoadStat struct {
	Available bool
	Load1     float64
	Load5     float64
	Load15    float64
}

LoadStat represents system load averages.

func ParseLoadavg

func ParseLoadavg(content string) LoadStat

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

func ParseMeminfo(content string) MemStat

ParseMeminfo parses /proc/meminfo content. Exported for testing.

type NetworkStat

type NetworkStat struct {
	Available     bool
	RxBytesPerSec float64
	TxBytesPerSec float64
}

NetworkStat represents network throughput calculated from counter deltas.

type Stats

type Stats struct {
	CPU     CPUStat
	Memory  MemStat
	Disk    DiskStat
	Load    LoadStat
	GPU     GPUStat
	Network NetworkStat
}

Stats holds a snapshot of all system statistics.

func Collect

func Collect() Stats

Collect runs a single collection cycle and returns the result. Useful for testing without starting the background goroutine.

Jump to

Keyboard shortcuts

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