collector

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUInfo

type CPUInfo struct {
	TotalPercent float64   `json:"total_percent"`
	AvgPercent   float64   `json:"avg_percent"`
	MaxPercent   float64   `json:"max_percent"`
	FreqMHz      float64   `json:"frequency_mhz"`
	PerCore      []float64 `json:"per_core"`
	History      []float64 `json:"history"`
}

type Collector

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

Collector periodically gathers system data and broadcasts snapshots.

func New

func New(interval time.Duration) *Collector

New creates a new Collector that refreshes at the given interval.

func (*Collector) Latest

func (c *Collector) Latest() *Snapshot

Latest returns the most recent snapshot (for REST API).

func (*Collector) LatestJSON added in v0.1.2

func (c *Collector) LatestJSON() []byte

LatestJSON returns the pre-serialized JSON of the latest snapshot.

func (*Collector) LatestJSONWithProcesses added in v0.1.2

func (c *Collector) LatestJSONWithProcesses(ctx context.Context) []byte

LatestJSONWithProcesses returns the latest snapshot JSON, hydrating process details on demand when the cached snapshot only contains the total count.

func (*Collector) LatestWithProcesses added in v0.1.2

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

LatestWithProcesses returns the most recent snapshot, hydrating process details on demand when the cached snapshot only contains the total count.

func (*Collector) ReleaseProcesses added in v0.1.2

func (c *Collector) ReleaseProcesses()

ReleaseProcesses decrements the process consumer counter.

func (*Collector) RequestProcesses added in v0.1.2

func (c *Collector) RequestProcesses()

RequestProcesses increments the process consumer counter. When the counter is >0, collectOnce will gather process data.

func (*Collector) Start

func (c *Collector) Start(ctx context.Context)

Start begins the collection loop. Blocks until Stop is called.

func (*Collector) Stop

func (c *Collector) Stop()

Stop signals the collector to stop.

func (*Collector) Subscribe

func (c *Collector) Subscribe(id string) <-chan *Snapshot

Subscribe registers a subscriber and returns a channel for snapshots.

func (*Collector) Unsubscribe

func (c *Collector) Unsubscribe(id string)

Unsubscribe removes a subscriber.

type DiskIO

type DiskIO struct {
	Device       string `json:"device"`
	ReadByteSec  uint64 `json:"read_bytes_sec"`
	WriteByteSec uint64 `json:"write_bytes_sec"`
	IOPS         uint64 `json:"iops"`
}

type DiskInfo

type DiskInfo struct {
	Filesystems []Filesystem `json:"filesystems"`
	IO          []DiskIO     `json:"io"`
}

type Filesystem

type Filesystem struct {
	Mount   string  `json:"mount"`
	Device  string  `json:"device"`
	FSType  string  `json:"fstype"`
	Total   uint64  `json:"total"`
	Used    uint64  `json:"used"`
	Percent float64 `json:"percent"`
}

type HealthInfo added in v0.1.6

type HealthInfo struct {
	Score    int             `json:"score"`
	Warnings []HealthWarning `json:"warnings"`
}

type HealthWarning added in v0.1.6

type HealthWarning struct {
	Level   string `json:"level"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

type LoadInfo

type LoadInfo struct {
	Load1  float64 `json:"load1"`
	Load5  float64 `json:"load5"`
	Load15 float64 `json:"load15"`
}

type MemoryInfo

type MemoryInfo 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"`
}

type NetInterface

type NetInterface struct {
	Name        string  `json:"name"`
	DownloadSec uint64  `json:"download_sec"`
	UploadSec   uint64  `json:"upload_sec"`
	IPv4        string  `json:"ipv4,omitempty"`
	RxBytes     uint64  `json:"rx_bytes,omitempty"`
	TxBytes     uint64  `json:"tx_bytes,omitempty"`
	RxErrors    uint64  `json:"rx_errors,omitempty"`
	TxErrors    uint64  `json:"tx_errors,omitempty"`
	RxDrops     uint64  `json:"rx_drops,omitempty"`
	TxDrops     uint64  `json:"tx_drops,omitempty"`
	RxErrRate   float64 `json:"rx_err_rate,omitempty"`
	TxErrRate   float64 `json:"tx_err_rate,omitempty"`
	RxDropRate  float64 `json:"rx_drop_rate,omitempty"`
	TxDropRate  float64 `json:"tx_drop_rate,omitempty"`
}

type NetworkInfo

type NetworkInfo struct {
	TotalDownloadSec uint64            `json:"total_download_sec"`
	TotalUploadSec   uint64            `json:"total_upload_sec"`
	TCPConns         uint32            `json:"tcp_connections"`
	TCPStates        map[string]uint32 `json:"tcp_states,omitempty"`
	UDPConns         uint32            `json:"udp_connections"`
	ConntrackCount   uint32            `json:"conntrack_count,omitempty"`
	ConntrackMax     uint32            `json:"conntrack_max,omitempty"`
	Interfaces       []NetInterface    `json:"interfaces"`
}

type ProcessEntry

type ProcessEntry struct {
	PID           int32   `json:"pid"`
	PPID          int32   `json:"ppid,omitempty"`
	Name          string  `json:"name"`
	User          string  `json:"user"`
	CPUPercent    float64 `json:"cpu_percent"`
	MemPercent    float32 `json:"mem_percent"`
	RSS           uint64  `json:"rss"`
	Status        string  `json:"status"`
	Command       string  `json:"command"`
	Threads       int32   `json:"threads,omitempty"`
	Nice          int32   `json:"nice,omitempty"`
	Uptime        uint64  `json:"uptime,omitempty"`
	StartedAtUnix int64   `json:"started_at_unix,omitempty"`
}

type ProcessInfo

type ProcessInfo struct {
	Total int            `json:"total"`
	List  []ProcessEntry `json:"list"`
}

type Snapshot

type Snapshot struct {
	Timestamp time.Time   `json:"timestamp"`
	System    SystemInfo  `json:"system"`
	CPU       CPUInfo     `json:"cpu"`
	Memory    MemoryInfo  `json:"memory"`
	Disk      DiskInfo    `json:"disk"`
	Network   NetworkInfo `json:"network"`
	Load      LoadInfo    `json:"load"`
	Processes ProcessInfo `json:"processes"`
	Health    HealthInfo  `json:"health"`
}

Snapshot represents a complete system state at a point in time.

func BuildSnapshot

func BuildSnapshot(
	static vminfo.StaticInfo,
	stats vminfo.RuntimeStats,
	procs []vminfo.ProcessInfo,
	cpuHistory []float64,
) Snapshot

BuildSnapshot creates a Snapshot from existing vminfo package data.

type SystemInfo

type SystemInfo struct {
	Hostname  string `json:"hostname"`
	OS        string `json:"os"`
	Kernel    string `json:"kernel"`
	Arch      string `json:"arch"`
	CPUModel  string `json:"cpu_model"`
	Cores     int    `json:"cores"`
	UptimeSec uint64 `json:"uptime_seconds"`
	UptimeStr string `json:"uptime_human"`
}

Jump to

Keyboard shortcuts

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