collector

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 10 Imported by: 0

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

type NetworkInfo

type NetworkInfo struct {
	TotalDownloadSec uint64         `json:"total_download_sec"`
	TotalUploadSec   uint64         `json:"total_upload_sec"`
	TCPConns         uint32         `json:"tcp_connections"`
	UDPConns         uint32         `json:"udp_connections"`
	Interfaces       []NetInterface `json:"interfaces"`
}

type ProcessEntry

type ProcessEntry struct {
	PID        int32   `json:"pid"`
	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"`
}

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

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