Documentation
¶
Overview ¶
Package diag provides a lightweight, always-on runtime watchdog that samples process resource metrics (goroutine count, heap usage) on an interval and records a diagnostic when a threshold is crossed. It exists to catch runaway resource growth — leaked goroutines or unbounded memory — early, and to leave a durable, actionable artifact (including a full goroutine stack dump) even when structured logging via GRUT_LOG is not enabled.
The watchdog is cheap: one runtime.ReadMemStats and runtime.NumGoroutine per interval (default 60s), so it is safe to run for the entire session.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
Timestamp time.Time
Kind string // kindGoroutines or kindHeap
Message string
Goroutines int
Baseline int
HeapInuseBytes uint64
NumGC uint32
}
Alert describes a threshold breach detected by the watchdog.
type Thresholds ¶
type Thresholds struct {
// GoroutineFloor is an absolute goroutine count that always triggers an
// alert regardless of the startup baseline.
GoroutineFloor int
// GoroutineGrowth triggers an alert when the live goroutine count exceeds
// GoroutineGrowth * baseline (and is at least GoroutineGrowthMin).
GoroutineGrowth float64
// GoroutineGrowthMin guards the growth check so a tiny baseline cannot
// produce alerts at harmless goroutine counts.
GoroutineGrowthMin int
// HeapInuseBytes triggers an alert when heap-in-use exceeds this many bytes.
HeapInuseBytes uint64
// Cooldown is the minimum time between alerts of the same kind.
Cooldown time.Duration
}
Thresholds configures when the watchdog reports.
func DefaultThresholds ¶
func DefaultThresholds() Thresholds
DefaultThresholds returns the built-in threshold configuration.
type Watchdog ¶
type Watchdog struct {
// contains filtered or unexported fields
}
Watchdog samples runtime metrics and reports threshold breaches.