sysinfo

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sysinfo gathers OS-level resource metrics (memory, swap, disk, load) and evaluates them against configurable thresholds to produce alerts at WARNING and DANGER severity levels.

Platform support uses build tags: Linux reads /proc, macOS shells out to sysctl/vm_stat, and other platforms return Supported: false gracefully.

Index

Constants

View Source
const (
	ResourceMemory = "memory"
	ResourceSwap   = "swap"
	ResourceDisk   = "disk"
	ResourceLoad   = "load"
)

Resource name constants for threshold evaluation.

Variables

This section is empty.

Functions

func FormatGiB

func FormatGiB(bytes uint64) string

FormatGiB formats bytes as a GiB value with one decimal place (e.g. "14.7").

Parameters:

  • bytes: Value in bytes to format

Returns:

  • string: Formatted GiB string (e.g. "14.7")

Types

type DiskInfo

type DiskInfo struct {
	TotalBytes uint64
	UsedBytes  uint64
	Path       string
	Supported  bool
	Err        error
}

DiskInfo holds filesystem usage for a given path.

type LoadInfo

type LoadInfo struct {
	Load1     float64
	Load5     float64
	Load15    float64
	NumCPU    int
	Supported bool
}

LoadInfo holds system load averages and CPU count.

type MemInfo

type MemInfo struct {
	TotalBytes     uint64
	UsedBytes      uint64
	SwapTotalBytes uint64
	SwapUsedBytes  uint64
	Supported      bool
}

MemInfo holds memory and swap usage metrics.

type ResourceAlert

type ResourceAlert struct {
	Severity Severity
	Resource string
	Message  string
}

ResourceAlert describes a single threshold breach.

func Evaluate

func Evaluate(snap Snapshot) []ResourceAlert

Evaluate checks a snapshot against resource thresholds and returns any alerts. Unsupported or zero-total resources are silently skipped.

Thresholds:

  • Memory: WARNING >= 80%, DANGER >= 90%
  • Swap: WARNING >= 50%, DANGER >= 75%
  • Disk: WARNING >= 85%, DANGER >= 95%
  • Load: WARNING >= 0.8x CPUs, DANGER >= 1.5x CPUs

Parameters:

  • snap: System resource snapshot to evaluate

Returns:

  • []ResourceAlert: Alerts for any resources exceeding thresholds

type Severity

type Severity int

Severity represents the urgency level of a resource alert.

const (
	SeverityOK      Severity = iota // No concern
	SeverityWarning                 // Approaching limits
	SeverityDanger                  // Critically low resources
)

func MaxSeverity

func MaxSeverity(alerts []ResourceAlert) Severity

MaxSeverity returns the highest severity among the given alerts.

Returns SeverityOK when the slice is empty.

Parameters:

  • alerts: Resource alerts to evaluate

Returns:

  • Severity: Highest severity found, or SeverityOK if empty

func SeverityFor

func SeverityFor(alerts []ResourceAlert, resource string) Severity

SeverityFor returns the severity level for a given resource name from an alert list. Returns SeverityOK if no alert matches.

Parameters:

  • alerts: list of resource alerts to search
  • resource: resource name to match (e.g., "memory", "disk")

Returns:

  • Severity: the severity level for the resource

func (Severity) String

func (s Severity) String() string

String returns the lowercase label for the severity level.

type Snapshot

type Snapshot struct {
	Memory MemInfo
	Disk   DiskInfo
	Load   LoadInfo
}

Snapshot captures a point-in-time view of system resources.

func Collect

func Collect() Snapshot

Collect gathers a resource snapshot.

Disk usage is checked for the filesystem containing the current working directory.

Returns:

  • Snapshot: Memory, disk, and load metrics

Jump to

Keyboard shortcuts

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