collector

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeLoadAvg  = "M LOADAVG"
	ModeMemStats = "M MEMSTATS"
	ModeNetStats = "M NETSTATS"
	ModeCPUStats = "M CPUSTATS"
)

Protocol mode markers (line-based, sent by remote script)

Variables

View Source
var LinuxScript []byte

LinuxScript contains the embedded loadbars-remote.sh script for Linux hosts

Functions

func Run

func Run(ctx context.Context, host string, cfg *config.Config, store StatsStore) error

Run starts a collector for one host: runs the embedded remote script (local or over SSH) and parses the stream into store. Host may be "host" or "host:user". It runs until ctx is cancelled or the command exits. The script is embedded in the binary; no external script file is required.

Types

type CPULine

type CPULine struct {
	Name                                                                    string
	User, Nice, System, Idle, Iowait, IRQ, SoftIRQ, Steal, Guest, GuestNice int64
}

CPULine is one line of /proc/stat: cpu name + counters (user, nice, system, idle, ...).

func ParseCPULine

func ParseCPULine(line string) (CPULine, error)

ParseCPULine parses a /proc/stat line: "cpu 100 0 50 200 0 0 0 0 0 0" (name + 10 numbers). Older kernels may have fewer fields; missing ones are treated as 0.

func (*CPULine) Total

func (c *CPULine) Total() int64

Total returns sum of all CPU counters.

type LoadAvg

type LoadAvg struct {
	Load1, Load5, Load15 string
}

LoadAvg is 1/5/15 min load average.

func ParseLoadAvg

func ParseLoadAvg(line string) LoadAvg

ParseLoadAvg parses "1.0;0.5;0.2" into Load1, Load5, Load15.

type MemLine

type MemLine struct {
	Key   string
	Value int64
}

MemLine is one key from /proc/meminfo (e.g. MemTotal, MemFree).

func ParseMemLine

func ParseMemLine(line string) (MemLine, bool)

ParseMemLine parses a /proc/meminfo line: "MemTotal: 123456 kB".

type NetLine

type NetLine struct {
	Iface string
	B     int64 // rx bytes
	Tb    int64 // tx bytes
	P     int64
	Tp    int64
	E     int64
	Te    int64
	D     int64
	Td    int64
}

NetLine is one interface line: iface and key=value pairs (b, tb, p, tp, e, te, d, td).

func ParseNetLine

func ParseNetLine(line string) (NetLine, error)

ParseNetLine parses a protocol net line: "eth0:b=0;tb=0;p=0;tp=0 e=0;te=0;d=0;td=0". There may be a space between first block (b,tb,p,tp) and second (e,te,d,td).

type StatsStore

type StatsStore interface {
	SetLoadAvg(host, load1, load5, load15 string)
	SetCPU(host, name string, line CPULine)
	SetMem(host, key string, value int64)
	SetNet(host, iface string, net NetLine, stamp float64)
}

StatsStore is the interface for receiving parsed stats (implemented by app).

Jump to

Keyboard shortcuts

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