Help us shape the future of Go! Take the 2026 Go Developer Survey

sysinfo

package
v1.65.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const NA = "n/a"

NA is the display sentinel for values that could not be determined.

Variables

View Source
var (
	// LookPath is mockable for testing.
	LookPath = execx.LookPath
	// ReadFile is mockable for testing.
	ReadFile = os.ReadFile
	// RuntimeGOOS is mockable for testing.
	RuntimeGOOS = runtime.GOOS
	// OSReleasePaths are the standard paths checked for distro identification.
	OSReleasePaths = []string{"/etc/os-release", "/usr/lib/os-release"}
)

Functions

func FormatUptime added in v1.57.0

func FormatUptime(seconds uint64) string

FormatUptime renders seconds in compact human form.

func HasApt

func HasApt() bool

HasApt returns true if 'apt-get' or 'apt' is on PATH.

func HasBrew

func HasBrew() bool

HasBrew returns true if the 'brew' executable is on PATH.

func HasDNF

func HasDNF() bool

HasDNF returns true if 'dnf' or 'dnf5' is on PATH.

func HasDocker

func HasDocker() bool

HasDocker returns true if the 'docker' executable is on PATH.

func HasFlatpak

func HasFlatpak() bool

HasFlatpak returns true if the 'flatpak' executable is on PATH.

Types

type DistroInfo

type DistroInfo struct {
	ID         string
	IDLike     []string
	VersionID  string
	Name       string
	PrettyName string
	RawOS      string // runtime.GOOS
}

DistroInfo contains parsed distribution information from /etc/os-release.

func Detect

func Detect() DistroInfo

Detect probes the operating system and Linux distribution metadata.

func (DistroInfo) IsDebianUbuntu

func (d DistroInfo) IsDebianUbuntu() bool

IsDebianUbuntu returns true if running on Ubuntu, Debian, or derivative.

func (DistroInfo) IsFedora

func (d DistroInfo) IsFedora() bool

IsFedora returns true if running on Fedora or RHEL/CentOS family.

func (DistroInfo) IsLinux

func (d DistroInfo) IsLinux() bool

IsLinux returns true if running on Linux.

func (DistroInfo) IsMacOS

func (d DistroInfo) IsMacOS() bool

IsMacOS returns true if running on Darwin/macOS.

func (DistroInfo) IsRaspberryPi

func (d DistroInfo) IsRaspberryPi() bool

IsRaspberryPi returns true if running on Raspbian / Raspberry Pi OS.

type SystemInfo added in v1.57.0

type SystemInfo struct {
	Hostname         string   `json:"hostname"           yaml:"hostname"`
	OS               string   `json:"os"                 yaml:"os"`
	Distro           string   `json:"distro"             yaml:"distro"`
	Kernel           string   `json:"kernel"             yaml:"kernel"`
	Arch             string   `json:"arch"               yaml:"arch"`
	CPUModel         string   `json:"cpu_model"          yaml:"cpu_model"`
	CPUCoresLogical  int      `json:"cpu_cores_logical"  yaml:"cpu_cores_logical"`
	CPUCoresPhysical int      `json:"cpu_cores_physical" yaml:"cpu_cores_physical"`
	MemTotalBytes    uint64   `json:"mem_total_bytes"    yaml:"mem_total_bytes"`
	MemUsedBytes     uint64   `json:"mem_used_bytes"     yaml:"mem_used_bytes"`
	MemUsedPercent   float64  `json:"mem_used_percent"   yaml:"mem_used_percent"`
	DiskPath         string   `json:"disk_path"          yaml:"disk_path"`
	DiskTotalBytes   uint64   `json:"disk_total_bytes"   yaml:"disk_total_bytes"`
	DiskUsedBytes    uint64   `json:"disk_used_bytes"    yaml:"disk_used_bytes"`
	DiskFreeBytes    uint64   `json:"disk_free_bytes"    yaml:"disk_free_bytes"`
	DiskUsedPercent  float64  `json:"disk_used_percent"  yaml:"disk_used_percent"`
	UptimeSeconds    uint64   `json:"uptime_seconds"     yaml:"uptime_seconds"`
	LocalIPs         []string `json:"local_ips"          yaml:"local_ips"`
	Gateway          string   `json:"gateway"            yaml:"gateway"`
	DNS              []string `json:"dns"                yaml:"dns"`
	PublicIP         string   `json:"public_ip"          yaml:"public_ip"`
	TailscaleIP      string   `json:"tailscale_ip"       yaml:"tailscale_ip"`
	GPU              string   `json:"gpu"                yaml:"gpu"`
	Battery          string   `json:"battery"            yaml:"battery"`
	Temperature      string   `json:"temperature"        yaml:"temperature"`
	DeviceModel      string   `json:"device_model"       yaml:"device_model"`
}

SystemInfo holds best-effort diagnostics for one machine. Empty strings, zeroes, and empty slices mean "could not be determined" and render as NA.

func Collect added in v1.57.0

func Collect(ctx context.Context) SystemInfo

Collect gathers best-effort system diagnostics. It never returns an error: fields that cannot be determined keep their zero values for NA rendering.

func (SystemInfo) CPUDisplay added in v1.57.0

func (s SystemInfo) CPUDisplay() string

CPUDisplay renders "model (N cores)" with graceful degradation.

func (SystemInfo) DiskDisplay added in v1.57.0

func (s SystemInfo) DiskDisplay() string

DiskDisplay renders "used / total (pct%)" or "total" when use is unknown.

func (SystemInfo) MemoryDisplay added in v1.57.0

func (s SystemInfo) MemoryDisplay() string

MemoryDisplay renders "used / total (pct%)" or "total" when use is unknown.

func (SystemInfo) UptimeDisplay added in v1.57.0

func (s SystemInfo) UptimeDisplay() string

UptimeDisplay renders seconds as "3d 4h 12m".

Jump to

Keyboard shortcuts

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