monitoring

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(bytes uint64) string

FormatBytes formats bytes into human-readable string

func FormatPercent

func FormatPercent(percent float64) string

FormatPercent formats a percentage value

Types

type CPUStats

type CPUStats struct {
	UsagePercent  float64 `json:"usage_percent"`
	Cores         int     `json:"cores"`
	UserPercent   float64 `json:"user_percent"`
	SystemPercent float64 `json:"system_percent"`
	IdlePercent   float64 `json:"idle_percent"`
}

CPUStats represents CPU usage information

type Collector

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

Collector manages resource collection and history

func NewCollector

func NewCollector(includeContainers bool, maxHistory int) *Collector

NewCollector creates a new resource collector

func (*Collector) CheckAlerts

func (c *Collector) CheckAlerts() []ResourceAlert

CheckAlerts checks for resource usage alerts

func (*Collector) ClearHistory

func (c *Collector) ClearHistory()

ClearHistory clears the collected statistics history

func (*Collector) GetAverages

func (c *Collector) GetAverages(duration time.Duration) *SystemStats

GetAverages calculates average statistics over a time period

func (*Collector) GetCurrent

func (c *Collector) GetCurrent() (*SystemStats, error)

GetCurrent returns the most recent system statistics

func (*Collector) GetHistory

func (c *Collector) GetHistory() []SystemStats

GetHistory returns the collected statistics history

func (*Collector) GetHistorySince

func (c *Collector) GetHistorySince(since time.Time) []SystemStats

GetHistorySince returns statistics collected since the given time

func (*Collector) SetInterval

func (c *Collector) SetInterval(interval time.Duration)

SetInterval updates the collection interval

func (*Collector) Start

func (c *Collector) Start()

Start begins collecting system statistics

func (*Collector) Stop

func (c *Collector) Stop()

Stop stops collecting statistics

type ContainerStats

type ContainerStats struct {
	ID         string  `json:"id"`
	Name       string  `json:"name"`
	Status     string  `json:"status"`
	CPUPercent float64 `json:"cpu_percent"`
	MemUsage   uint64  `json:"mem_usage"`
	MemLimit   uint64  `json:"mem_limit"`
	MemPercent float64 `json:"mem_percent"`
	NetIO      string  `json:"net_io"`
	BlockIO    string  `json:"block_io"`
}

ContainerStats represents Docker container statistics

type DiskStats

type DiskStats struct {
	Total       uint64  `json:"total"`
	Used        uint64  `json:"used"`
	Free        uint64  `json:"free"`
	UsedPercent float64 `json:"used_percent"`
	Mountpoint  string  `json:"mountpoint"`
}

DiskStats represents disk usage information

type LoadStats

type LoadStats struct {
	Load1  float64 `json:"load_1"`
	Load5  float64 `json:"load_5"`
	Load15 float64 `json:"load_15"`
}

LoadStats represents system load averages

type MemoryStats

type MemoryStats struct {
	Total       uint64  `json:"total"`
	Used        uint64  `json:"used"`
	Free        uint64  `json:"free"`
	Available   uint64  `json:"available"`
	UsedPercent float64 `json:"used_percent"`
	Cached      uint64  `json:"cached"`
	Buffers     uint64  `json:"buffers"`
	SwapTotal   uint64  `json:"swap_total"`
	SwapUsed    uint64  `json:"swap_used"`
	SwapFree    uint64  `json:"swap_free"`
}

MemoryStats represents memory usage information

type Monitor

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

Monitor provides system monitoring capabilities

func NewMonitor

func NewMonitor(includeContainers bool) *Monitor

NewMonitor creates a new system monitor

func (*Monitor) GetSystemStats

func (m *Monitor) GetSystemStats() (*SystemStats, error)

GetSystemStats retrieves current system statistics

func (*Monitor) GetTopProcesses

func (m *Monitor) GetTopProcesses(count int, sortBy string) ([]ProcessInfo, error)

GetTopProcesses returns the top N processes by CPU or memory usage

func (*Monitor) StreamStats

func (m *Monitor) StreamStats(ctx context.Context, interval time.Duration, ch chan<- *SystemStats)

StreamStats continuously monitors and sends system statistics

type NetworkStats

type NetworkStats struct {
	BytesRecv   uint64 `json:"bytes_recv"`
	BytesSent   uint64 `json:"bytes_sent"`
	PacketsRecv uint64 `json:"packets_recv"`
	PacketsSent uint64 `json:"packets_sent"`
}

NetworkStats represents network statistics

type ProcessInfo

type ProcessInfo struct {
	PID        int     `json:"pid"`
	Name       string  `json:"name"`
	User       string  `json:"user"`
	CPUPercent float64 `json:"cpu_percent"`
	MemoryKB   uint64  `json:"memory_kb"`
	State      string  `json:"state"`
	Command    string  `json:"command"`
}

ProcessInfo represents information about a single process

type ProcessStats

type ProcessStats struct {
	Total    int `json:"total"`
	Running  int `json:"running"`
	Sleeping int `json:"sleeping"`
	Stopped  int `json:"stopped"`
	Zombie   int `json:"zombie"`
}

ProcessStats represents process information

type ResourceAlert

type ResourceAlert struct {
	Type      string    `json:"type"`
	Severity  string    `json:"severity"`
	Message   string    `json:"message"`
	Value     float64   `json:"value"`
	Threshold float64   `json:"threshold"`
	Timestamp time.Time `json:"timestamp"`
}

ResourceAlert represents a resource usage alert

type SystemStats

type SystemStats struct {
	Timestamp   time.Time        `json:"timestamp"`
	CPU         CPUStats         `json:"cpu"`
	Memory      MemoryStats      `json:"memory"`
	Disk        DiskStats        `json:"disk"`
	LoadAverage LoadStats        `json:"load_average"`
	Processes   ProcessStats     `json:"processes"`
	Network     NetworkStats     `json:"network"`
	Containers  []ContainerStats `json:"containers,omitempty"`
}

SystemStats represents system resource usage

Jump to

Keyboard shortcuts

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