anomaly

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDeviationPct

func CalculateDeviationPct(val, baseline float64) float64

CalculateDeviationPct computes relative percentage change from baseline.

func CalculateZScore

func CalculateZScore(val, mean, stddev float64) float64

CalculateZScore computes Z-score: (x - mean) / stddev.

Types

type Detector

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

Detector tracks multiple metric streams and identifies statistical anomalies using Z-score and EWMA.

func NewDetector

func NewDetector(cfg *config.AnomalyConfig) *Detector

NewDetector creates a statistical anomaly detector.

func (*Detector) Feed

func (d *Detector) Feed(metric string, value float64, ts time.Time) model.AnomalyScore

Feed ingests a single metric point, updates baseline stats, and evaluates anomaly score.

func (*Detector) FeedSnapshot

func (d *Detector) FeedSnapshot(snapshot *model.SystemSnapshot) *model.AnomalyReport

FeedSnapshot extracts all standard metrics from a snapshot and evaluates anomalies.

func (*Detector) Reset

func (d *Detector) Reset()

Reset clears all baseline metrics.

type EWMATracker

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

EWMATracker computes Exponentially Weighted Moving Average.

func NewEWMATracker

func NewEWMATracker(alpha float64) *EWMATracker

NewEWMATracker creates an EWMA calculator with smoothing factor alpha (0.0 < alpha <= 1.0).

func (*EWMATracker) Update

func (e *EWMATracker) Update(val float64) float64

Update incorporates a new sample and returns the new EWMA.

func (*EWMATracker) Value

func (e *EWMATracker) Value() float64

Value returns the current EWMA.

type MetricStream

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

MetricStream holds statistical estimators for a single time series metric.

type RollingWindow

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

RollingWindow maintains a fixed-size ring buffer for statistical calculations.

func NewRollingWindow

func NewRollingWindow(capacity int) *RollingWindow

NewRollingWindow creates a rolling window buffer with maximum capacity.

func (*RollingWindow) Add

func (rw *RollingWindow) Add(val float64)

Add appends a new data point into the rolling window.

func (*RollingWindow) Count

func (rw *RollingWindow) Count() int

Count returns the current number of samples in the window.

func (*RollingWindow) Mean

func (rw *RollingWindow) Mean() float64

Mean returns the arithmetic mean of values in the window.

func (*RollingWindow) MinMax

func (rw *RollingWindow) MinMax() (float64, float64)

MinMax returns minimum and maximum values in the window.

func (*RollingWindow) StdDev

func (rw *RollingWindow) StdDev() float64

StdDev computes the sample standard deviation.

func (*RollingWindow) Values

func (rw *RollingWindow) Values() []float64

Values returns a copy of current elements in the window.

Jump to

Keyboard shortcuts

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