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

sysload

package
v0.2.43 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package sysload samples this machine's load for the owner Overview: CPU, memory, network throughput, GPU (when the platform reports it) and Ether's own CPU and memory. A background loop keeps a short history so the page can draw recent trends the moment it opens.

CPU, memory, network and process figures come from gopsutil, which is pure Go on Linux, macOS and Windows. GPU figures are best effort (see gpu.go) and are only collected while someone is looking, because some platforms need a helper process per reading.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counters

type Counters struct {
	CPUBusy, CPUTotal float64 // seconds across all cores
	MemUsed, MemTotal uint64
	SwapUsed          uint64
	SwapTotal         uint64
	NetRx, NetTx      uint64  // bytes on physical interfaces
	ProcCPU           float64 // this process's CPU seconds
	ProcRSS           uint64
	Load              []float64
}

Counters are cumulative readings; Sampler turns them into rates.

type GPU

type GPU struct {
	Name string `json:"name"`
	// Util is overall utilisation in percent.
	Util *float64 `json:"util,omitempty"`
	// Encoder and Decoder are the video engines' utilisation (NVIDIA).
	Encoder  *float64 `json:"encoder,omitempty"`
	Decoder  *float64 `json:"decoder,omitempty"`
	MemUsed  uint64   `json:"memUsed,omitempty"`
	MemTotal uint64   `json:"memTotal,omitempty"`
}

GPU is one graphics adapter's current state. Unknown figures are nil or 0.

type Options

type Options struct {
	Source Source
	// Interval between readings (default 2s).
	Interval time.Duration
	// History is how many readings to keep (default 150: five minutes).
	History int
	// GPUInterval spaces GPU readings (default 5s).
	GPUInterval time.Duration
	// GPUIdle stops GPU readings this long after the last Snapshot
	// (default 1m).
	GPUIdle time.Duration
	Logger  *slog.Logger
	Now     func() time.Time
}

Options configure a Sampler.

type Sample

type Sample struct {
	At       time.Time `json:"at"`
	CPU      float64   `json:"cpu"`
	MemUsed  uint64    `json:"memUsed"`
	NetRxBps float64   `json:"netRxBps"`
	NetTxBps float64   `json:"netTxBps"`
	ProcCPU  float64   `json:"procCpu"`
	ProcRSS  uint64    `json:"procRss"`
	// GPU is the busiest GPU's utilisation, when known.
	GPU *float64 `json:"gpu,omitempty"`
}

Sample is one reading. Rates and percentages cover the interval since the previous reading; percentages are of the whole machine (all cores).

type Sampler

type Sampler struct {
	// contains filtered or unexported fields
}

Sampler keeps recent readings.

func New

func New(opts Options) *Sampler

New builds a Sampler; call Run to start sampling.

func (*Sampler) Run

func (s *Sampler) Run(ctx context.Context)

Run samples until ctx ends.

func (*Sampler) Sample

func (s *Sampler) Sample(ctx context.Context)

Sample takes one reading now.

func (*Sampler) Snapshot

func (s *Sampler) Snapshot() Snapshot

Snapshot returns the current state and history, and keeps GPU readings running for a while.

type Snapshot

type Snapshot struct {
	Cores     int       `json:"cores"`
	MemTotal  uint64    `json:"memTotal"`
	SwapUsed  uint64    `json:"swapUsed"`
	SwapTotal uint64    `json:"swapTotal"`
	Load      []float64 `json:"load,omitempty"` // 1, 5 and 15 minutes; not on Windows
	// IntervalSeconds is the spacing of History.
	IntervalSeconds float64  `json:"intervalSeconds"`
	Current         *Sample  `json:"current,omitempty"`
	History         []Sample `json:"history"`
	GPUs            []GPU    `json:"gpus"`
	Error           string   `json:"error,omitempty"`
}

Snapshot is what the Overview shows.

type Source

type Source interface {
	Counters(ctx context.Context) (Counters, error)
	GPUs(ctx context.Context) ([]GPU, error)
}

Source reads the machine. The default reads the real one; tests fake it.

Jump to

Keyboard shortcuts

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