collector

package
v0.0.0-...-9759625 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

GPU polling shared across platforms: the cache cadence lives here and the probe is platform-specific (NVML everywhere except darwin).

Package collector polls system metrics into serializable snapshots. Snapshot fields are plain data so the struct can later cross a wire unchanged (remote monitoring is planned post-v1).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmdline

func Cmdline(ctx context.Context, pid int32) string

Cmdline returns the full command line of one process, for the process-detail view. It is deliberately on-demand: gopsutil spawns a `ps` subprocess per call on darwin, so this must never run in the collection loop.

Types

type Battery

type Battery struct {
	Percent  float64 `json:"percent"`
	Charging bool    `json:"charging"`
}

Battery is the main battery state; a nil pointer means the machine has no battery (or the platform does not report one).

type CPU

type CPU struct {
	Percent float64   `json:"percent"`
	FreqMHz float64   `json:"freq_mhz,omitempty"`
	Cores   []float64 `json:"cores"`
}

CPU is one CPU sample. Percent is the aggregate across all logical cores; Cores holds one percentage per logical core. FreqMHz is the current average clock and is 0 when the platform does not report it.

type Collector

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

Collector polls system metrics on demand. It is safe for concurrent use. The zero value is usable; use New to size the slow-metric cadence.

func New

func New(refresh time.Duration) *Collector

New returns a collector whose slow metrics are sampled at most once per slowInterval (floored at 5s, since they are costly on some platforms).

func (*Collector) Collect

func (c *Collector) Collect(ctx context.Context) Snapshot

Collect gathers one snapshot. Sections that fail are left zeroed; collection never fails wholesale. Rate-based metrics are deltas over the interval between Collect calls.

type Conn

type Conn struct {
	Local  string `json:"local"`  // ip:port (IPv6 bracketed)
	Remote string `json:"remote"` // ip:port, zero port for listeners
	State  string `json:"state"`
	PID    int32  `json:"pid,omitempty"`
}

Conn is one live TCP connection from the socket table. PID is best-effort — some platforms only resolve it with privileges, so it may stay zero and the process column renders as "—".

type Disk

type Disk struct {
	Device     string  `json:"device"`
	Mountpoint string  `json:"mountpoint"`
	FSType     string  `json:"fs_type"`
	Total      uint64  `json:"total"`
	Used       uint64  `json:"used"`
	Free       uint64  `json:"free"`
	Percent    float64 `json:"percent"`
}

Disk is one mounted filesystem.

type DiskIO

type DiskIO struct {
	Name        string  `json:"name"`
	ReadBytes   float64 `json:"read_bytes_per_s"`
	WriteBytes  float64 `json:"write_bytes_per_s"`
	ReadIOPS    float64 `json:"read_iops"`
	WriteIOPS   float64 `json:"write_iops"`
	BusyPercent float64 `json:"busy_percent"`
}

DiskIO is a per-device I/O rate sample (interval delta).

type Fan

type Fan struct {
	Name string  `json:"name"`
	RPM  float64 `json:"rpm"`
}

Fan is one cooling fan reading; RPM is 0 when the platform does not report it.

type GPU

type GPU struct {
	Index    int     `json:"index"`
	Name     string  `json:"name"`
	Util     float64 `json:"util_percent"`
	MemUsed  uint64  `json:"mem_used"`
	MemTotal uint64  `json:"mem_total"`
	TempC    float64 `json:"temp_c"`
}

GPU is one graphics adapter reading. Util is the percent of the whole adapter; memory figures are the adapter's own VRAM. A nil slice means no GPU reporting is available (or no adapter exists).

type Host

type Host struct {
	Hostname string        `json:"hostname"`
	OS       string        `json:"os"`
	Platform string        `json:"platform"`
	Kernel   string        `json:"kernel"`
	Arch     string        `json:"arch"`
	Uptime   time.Duration `json:"uptime"`
	Procs    int           `json:"procs"`
	Load     [3]float64    `json:"load"`
	Users    int           `json:"users"` // logged-in sessions
}

Host holds slow-changing system identity plus volatile load figures.

type Mem

type Mem struct {
	Total       uint64  `json:"total"`
	Used        uint64  `json:"used"`
	Available   uint64  `json:"available"`
	Percent     float64 `json:"percent"`
	SwapTotal   uint64  `json:"swap_total"`
	SwapUsed    uint64  `json:"swap_used"`
	SwapPercent float64 `json:"swap_percent"`
	ZramTotal   uint64  `json:"zram_total,omitempty"` // linux: compressed swap device
	ZramUsed    uint64  `json:"zram_used,omitempty"`
}

Mem is one memory sample.

type NetIface

type NetIface struct {
	Name          string  `json:"name"`
	RxRate        float64 `json:"rx_rate"` // bytes/s
	TxRate        float64 `json:"tx_rate"` // bytes/s
	RxRatePackets float64 `json:"rx_pps"`
	TxRatePackets float64 `json:"tx_pps"`
	RxDrop        float64 `json:"rx_drops"` // drops/s
	TxDrop        float64 `json:"tx_drops"` // drops/s
	RxTotal       uint64  `json:"rx_total"`
	TxTotal       uint64  `json:"tx_total"`
}

NetIface is a per-interface traffic sample (rates are interval deltas).

type Proc

type Proc struct {
	PID     int32   `json:"pid"`
	PPID    int32   `json:"ppid"`
	Name    string  `json:"name"`
	CPU     float64 `json:"cpu"`
	Mem     float64 `json:"mem"` // percent of physical memory
	RSS     uint64  `json:"rss"`
	User    string  `json:"user"`
	State   string  `json:"state"` // single letter: R S Z T I ...
	Threads int32   `json:"threads"`
	Nice    int8    `json:"nice"`
}

Proc is one process sample. CPU is an interval delta (htop-style) and can exceed 100 for multi-threaded processes.

type Sensor

type Sensor struct {
	Name  string  `json:"name"`
	TempC float64 `json:"temp_c"`
}

Sensor is one CPU-relevant temperature reading.

type Snapshot

type Snapshot struct {
	Time    time.Time  `json:"time"`
	Host    Host       `json:"host"`
	CPU     CPU        `json:"cpu"`
	Mem     Mem        `json:"mem"`
	Sensors []Sensor   `json:"sensors,omitempty"`
	Fans    []Fan      `json:"fans,omitempty"`
	Battery *Battery   `json:"battery,omitempty"`
	GPUs    []GPU      `json:"gpus,omitempty"`
	Procs   []Proc     `json:"procs,omitempty"`
	Disks   []Disk     `json:"disks,omitempty"`
	DiskIOs []DiskIO   `json:"disk_ios,omitempty"`
	Nets    []NetIface `json:"nets,omitempty"`
	Conns   []Conn     `json:"conns,omitempty"`
}

Snapshot is one sample of everything wrongtop shows.

type SnapshotMsg

type SnapshotMsg struct {
	Snap Snapshot
}

SnapshotMsg wraps a Snapshot for the bubbletea event loop.

Jump to

Keyboard shortcuts

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