Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Anomaly ¶
type Anomaly struct {
ID string `json:"id"`
Service string `json:"service"`
Metric string `json:"metric"`
Observed float64 `json:"observed"`
Expected float64 `json:"expected"` // baseline mean
Deviation float64 `json:"deviation"` // how many std devs away
Severity string `json:"severity"` // "info" (<2sigma), "warning" (2-3sigma), "critical" (>3sigma)
DetectedAt time.Time `json:"detected_at"`
Description string `json:"description"`
}
Anomaly represents a detected deviation from baseline behaviour.
type Baseline ¶
type Baseline struct {
Service string `json:"service"`
Metric string `json:"metric"` // "latency_p50", "error_rate", "throughput"
Mean float64 `json:"mean"`
StdDev float64 `json:"std_dev"`
SampleCount int `json:"sample_count"`
WindowStart time.Time `json:"window_start"`
WindowEnd time.Time `json:"window_end"`
}
Baseline represents learned normal behaviour for a service metric.
type Detector ¶
type Detector struct {
PersistFunc func(baselines []Baseline, anomalies []Anomaly) // called after mutations, if non-nil
// contains filtered or unexported fields
}
Detector maintains rolling baselines and detects anomalies.
func NewDetector ¶
NewDetector creates an anomaly detector with the given window and threshold.
func NewDetectorWithData ¶
func NewDetectorWithData(window time.Duration, threshold float64, baselines []Baseline, anomalies []Anomaly) *Detector
NewDetectorWithData creates an anomaly detector pre-loaded with baselines and anomalies.
func (*Detector) Check ¶
Check evaluates whether the given value is anomalous for the service+metric. Returns nil if the value is within normal bounds or if there's insufficient data.
func (*Detector) GetAnomalies ¶
GetAnomalies returns anomalies detected within the last N minutes.
func (*Detector) GetBaselines ¶
GetBaselines returns a copy of all current baselines.
func (*Detector) UpdateBaseline ¶
UpdateBaseline performs a rolling update of baseline statistics using Welford's online algorithm for numerically stable mean and variance.
func (*Detector) WhatChanged ¶
WhatChanged returns a human-readable explanation of what might have caused an anomaly, based on recent baseline changes across related metrics.