Documentation
¶
Overview ¶
Package hostmetrics collects host-level metrics (disk, RAM, CPU load, swap) via /proc reads and syscall.Statfs on Linux, with zero-value stubs on other platforms.
Index ¶
Constants ¶
const ( DiskWarnPct = 70.0 DiskCritPct = 85.0 RAMWarnPct = 80.0 RAMCritPct = 90.0 SwapWarnPct = 25.0 SwapCritPct = 50.0 CPULoadWarnRatio = 0.7 CPULoadCritRatio = 0.9 )
Threshold constants for alert evaluation.
Variables ¶
This section is empty.
Functions ¶
func ParseLoadAvg ¶
ParseLoadAvg parses the contents of /proc/loadavg and returns the 1-minute, 5-minute, and 15-minute load averages. Exported so tests can feed canned data without touching the filesystem.
func ParseMemInfo ¶
ParseMemInfo parses the contents of /proc/meminfo and returns MemTotal, MemAvailable, SwapTotal, and SwapFree in bytes. Exported so tests can feed canned data without touching the filesystem.
Types ¶
type Alert ¶
type Alert struct {
Resource string `json:"resource"`
Level AlertLevel `json:"level"`
Message string `json:"message"`
Value float64 `json:"value"`
Threshold float64 `json:"threshold"`
}
Alert represents a threshold breach for a monitored resource.
func EvaluateAlerts ¶
EvaluateAlerts checks the snapshot against threshold constants and returns any triggered alerts. Exported for testing.
type AlertLevel ¶
type AlertLevel string
AlertLevel classifies the severity of a resource alert.
const ( // AlertWarn indicates a resource is approaching its limit. AlertWarn AlertLevel = "warning" // AlertCritical indicates a resource is at or near its limit. AlertCritical AlertLevel = "critical" )
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector gathers host-level metrics on a 30-second interval.
func NewCollector ¶
NewCollector creates a Collector that reads disk stats from rootPath.
type Snapshot ¶
type Snapshot struct {
CollectedAt time.Time `json:"collected_at"`
// Disk
DiskTotalBytes uint64 `json:"disk_total_bytes"`
DiskUsedBytes uint64 `json:"disk_used_bytes"`
DiskPercent float64 `json:"disk_percent"`
// RAM
RAMTotalBytes uint64 `json:"ram_total_bytes"`
RAMUsedBytes uint64 `json:"ram_used_bytes"`
RAMAvailBytes uint64 `json:"ram_avail_bytes"`
RAMPercent float64 `json:"ram_percent"`
// Swap
SwapTotalBytes uint64 `json:"swap_total_bytes"`
SwapUsedBytes uint64 `json:"swap_used_bytes"`
SwapPercent float64 `json:"swap_percent"`
// CPU
LoadAvg1 float64 `json:"load_avg_1"`
LoadAvg5 float64 `json:"load_avg_5"`
LoadAvg15 float64 `json:"load_avg_15"`
NumCPU int `json:"num_cpu"`
// Alerts
Alerts []Alert `json:"alerts,omitempty"`
}
Snapshot captures host-level metrics at a point in time.