Documentation
¶
Index ¶
- Constants
- type Alert
- type AlertStore
- func (s *AlertStore) Active() []Alert
- func (s *AlertStore) Clear(typeName string, pid uint32)
- func (s *AlertStore) ClearAll() int
- func (s *AlertStore) ClearByKey(key string)
- func (s *AlertStore) ClearByType(typeName string) int
- func (s *AlertStore) History() []Alert
- func (s *AlertStore) Raise(a Alert) (Alert, bool)
- func (s *AlertStore) SetMaxActive(n int)
- func (s *AlertStore) Snooze(typeName string, pid uint32, until time.Time) bool
- type AnalysisContext
- type Detector
- type Engine
- type HungProcessDetector
- type MemoryLeakDetector
- type NetworkAnomalyDetector
- type NewProcessDetector
- type OrphanDetector
- type PortConflictDetector
- type ProcessActuator
- type RulesDetector
- type RunawayCPUDetector
- type Severity
- type SpawnStormDetector
Constants ¶
const ( EventAlertRaised = "anomaly.raised" EventAlertCleared = "anomaly.cleared" )
Event names emitted by the engine.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
ID string `json:"id"`
Type string `json:"type"`
Severity Severity `json:"severity"`
Title string `json:"title"`
Description string `json:"description"`
PID uint32 `json:"pid,omitempty"`
ProcessName string `json:"process_name,omitempty"`
Detected time.Time `json:"detected"`
Cleared *time.Time `json:"cleared,omitempty"`
Action string `json:"action,omitempty"`
Details map[string]any `json:"details,omitempty"`
}
Alert is a single anomaly detection event.
type AlertStore ¶
type AlertStore struct {
// contains filtered or unexported fields
}
AlertStore keeps active and historical alerts in a thread-safe ring.
func NewAlertStore ¶
func NewAlertStore(maxHistory int) *AlertStore
func (*AlertStore) Active ¶
func (s *AlertStore) Active() []Alert
Active returns a copy of the currently raised alerts.
func (*AlertStore) Clear ¶
func (s *AlertStore) Clear(typeName string, pid uint32)
Clear marks an active alert as cleared.
func (*AlertStore) ClearAll ¶
func (s *AlertStore) ClearAll() int
ClearAll empties the active alert set. Used by the "clear all" UI button to dig the user out of an alert flood without restarting the process. Returns the number of alerts removed.
func (*AlertStore) ClearByKey ¶ added in v0.2.0
func (s *AlertStore) ClearByKey(key string)
ClearByKey removes a specific active alert by its internal ID.
func (*AlertStore) ClearByType ¶
func (s *AlertStore) ClearByType(typeName string) int
ClearByType removes every active alert whose Type matches typeName, regardless of PID. Called when a detector gets disabled at runtime so the UI isn't left with stale entries that will never be re-raised or cleared. Returns the number of alerts removed.
func (*AlertStore) History ¶
func (s *AlertStore) History() []Alert
History returns a copy of the alert history ring.
func (*AlertStore) SetMaxActive ¶
func (s *AlertStore) SetMaxActive(n int)
SetMaxActive updates the active-alert cap. Called when config is (re)loaded so the user can tune how much alert noise the UI is allowed to hold. A value <= 0 disables the cap.
type AnalysisContext ¶
type AnalysisContext struct {
Now time.Time
Snapshot *metrics.SystemSnapshot
History []metrics.TimestampedSystem
Store *storage.Store
Cfg *config.Config
Alerts *AlertStore
Emitter *event.Emitter
Actuator ProcessActuator // may be nil in tests
}
AnalysisContext bundles the inputs each detector needs.
func (*AnalysisContext) ClearAlert ¶
func (a *AnalysisContext) ClearAlert(alertType string, pid uint32)
ClearAlert removes an active alert and emits a cleared event.
func (*AnalysisContext) RaiseAlert ¶
func (a *AnalysisContext) RaiseAlert(alert Alert)
raise is a helper used by detectors via AnalysisContext.RaiseAlert below.
type Detector ¶
type Detector interface {
Name() string
Analyze(ctx *AnalysisContext)
}
Detector is the interface implemented by every detector.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs all registered detectors on the configured cadence.
func (*Engine) SetActuator ¶
func (e *Engine) SetActuator(a ProcessActuator)
SetActuator wires the process controller so rule-based actions can kill / suspend processes. Without it, rules still evaluate and raise alerts but never execute the action.
type HungProcessDetector ¶
type HungProcessDetector struct {
// contains filtered or unexported fields
}
HungProcessDetector flags processes with no CPU and no IO progress for the configured window.
func NewHungProcessDetector ¶
func NewHungProcessDetector() *HungProcessDetector
func (*HungProcessDetector) Analyze ¶
func (d *HungProcessDetector) Analyze(ctx *AnalysisContext)
func (*HungProcessDetector) Name ¶
func (d *HungProcessDetector) Name() string
type MemoryLeakDetector ¶
type MemoryLeakDetector struct{}
MemoryLeakDetector flags processes whose working set grows linearly over a configurable window with high R² and average use above a threshold.
func NewMemoryLeakDetector ¶
func NewMemoryLeakDetector() *MemoryLeakDetector
func (*MemoryLeakDetector) Analyze ¶
func (d *MemoryLeakDetector) Analyze(ctx *AnalysisContext)
func (*MemoryLeakDetector) Name ¶
func (d *MemoryLeakDetector) Name() string
type NetworkAnomalyDetector ¶
type NetworkAnomalyDetector struct {
// contains filtered or unexported fields
}
NetworkAnomalyDetector flags either a connection-count blowup or a system-wide connection cap breach. Connection counts are smoothed using Welford's mean to compute a sigma-based threshold per-process.
func NewNetworkAnomalyDetector ¶
func NewNetworkAnomalyDetector() *NetworkAnomalyDetector
func (*NetworkAnomalyDetector) Analyze ¶
func (d *NetworkAnomalyDetector) Analyze(ctx *AnalysisContext)
func (*NetworkAnomalyDetector) Name ¶
func (d *NetworkAnomalyDetector) Name() string
type NewProcessDetector ¶
type NewProcessDetector struct {
// contains filtered or unexported fields
}
NewProcessDetector flags freshly spawned processes whose executable lives inside one of the configured suspicious paths. Each PID alerts at most once.
func NewNewProcessDetector ¶
func NewNewProcessDetector() *NewProcessDetector
func (*NewProcessDetector) Analyze ¶
func (d *NewProcessDetector) Analyze(ctx *AnalysisContext)
func (*NewProcessDetector) Name ¶
func (d *NewProcessDetector) Name() string
type OrphanDetector ¶
type OrphanDetector struct{}
OrphanDetector flags processes whose parent has died but which still consume resources above configurable thresholds.
func NewOrphanDetector ¶
func NewOrphanDetector() *OrphanDetector
func (*OrphanDetector) Analyze ¶
func (d *OrphanDetector) Analyze(ctx *AnalysisContext)
func (*OrphanDetector) Name ¶
func (d *OrphanDetector) Name() string
type PortConflictDetector ¶
type PortConflictDetector struct{}
PortConflictDetector flags TCP endpoints stuck in TIME_WAIT or CLOSE_WAIT past their respective thresholds. The "Since" field on PortBinding tells us how long the tuple has held its current state.
func NewPortConflictDetector ¶
func NewPortConflictDetector() *PortConflictDetector
func (*PortConflictDetector) Analyze ¶
func (d *PortConflictDetector) Analyze(ctx *AnalysisContext)
func (*PortConflictDetector) Name ¶
func (d *PortConflictDetector) Name() string
type ProcessActuator ¶
type ProcessActuator interface {
Kill(pid uint32, confirm bool) error
Suspend(pid uint32, confirm bool) error
}
ProcessActuator is the subset of the controller we call from rules. We keep the interface minimal so the anomaly package doesn't pull in the full controller dependency tree (it imports winapi which is Windows-only).
type RulesDetector ¶
type RulesDetector struct {
// contains filtered or unexported fields
}
RulesDetector evaluates user-defined rules from config. On every tick it walks the process list, checks each rule's match+when, and when a rule has been satisfied for at least `for` seconds, fires the configured action via ctx.Actuator. Each (rule,pid) respects a cooldown so a flapping process doesn't get killed in a loop.
func NewRulesDetector ¶
func NewRulesDetector() *RulesDetector
func (*RulesDetector) Analyze ¶
func (d *RulesDetector) Analyze(ctx *AnalysisContext)
func (*RulesDetector) Name ¶
func (d *RulesDetector) Name() string
type RunawayCPUDetector ¶
type RunawayCPUDetector struct {
// contains filtered or unexported fields
}
RunawayCPUDetector flags processes that sustain >= cpuThreshold for duration >= durationThreshold (warning) or criticalDuration (critical).
func NewRunawayCPUDetector ¶
func NewRunawayCPUDetector() *RunawayCPUDetector
func (*RunawayCPUDetector) Analyze ¶
func (d *RunawayCPUDetector) Analyze(ctx *AnalysisContext)
func (*RunawayCPUDetector) Name ¶
func (d *RunawayCPUDetector) Name() string
type SpawnStormDetector ¶
type SpawnStormDetector struct {
// contains filtered or unexported fields
}
SpawnStormDetector flags processes spawning excessive children rapidly. It tracks per-parent child counts within the last 60 seconds.
func NewSpawnStormDetector ¶
func NewSpawnStormDetector() *SpawnStormDetector
func (*SpawnStormDetector) Analyze ¶
func (d *SpawnStormDetector) Analyze(ctx *AnalysisContext)
func (*SpawnStormDetector) Name ¶
func (d *SpawnStormDetector) Name() string