Documentation
¶
Index ¶
- type AlertCallback
- type AlertState
- type BuiltinRulesEvaluator
- type CustomRuleEvaluator
- type Engine
- func (e *Engine) AddCallback(cb AlertCallback)
- func (e *Engine) Evaluate(ctx context.Context, snapshot *model.SystemSnapshot) ([]model.AlertEvent, []model.AlertEvent, error)
- func (e *Engine) GetActiveAlerts() []model.AlertEvent
- func (e *Engine) RegisterRule(rule model.AlertRule)
- func (e *Engine) Reset()
- func (e *Engine) Silence(ruleID string, dur time.Duration)
- type EvaluatedAlert
- type RuleEvaluator
- type StateTracker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlertCallback ¶
type AlertCallback func(event model.AlertEvent, isResolved bool)
AlertCallback is a function invoked when an alert fires or resolves.
type AlertState ¶
type AlertState struct {
RuleID string
FirstTriggeredAt time.Time
LastFiredAt time.Time
SilencedUntil time.Time
IsActive bool
CurrentEvent *model.AlertEvent
}
AlertState maintains the temporal lifecycle for a single alert rule.
type BuiltinRulesEvaluator ¶
type BuiltinRulesEvaluator struct{}
BuiltinRulesEvaluator evaluates standard thresholds configured in config.AlertsConfig.
func (*BuiltinRulesEvaluator) Evaluate ¶
func (b *BuiltinRulesEvaluator) Evaluate(snapshot *model.SystemSnapshot, cfg *config.Config) []EvaluatedAlert
Evaluate checks CPU, Memory, Disk, Process, and Network thresholds.
type CustomRuleEvaluator ¶
CustomRuleEvaluator evaluates user-defined AlertRules.
func (*CustomRuleEvaluator) Evaluate ¶
func (c *CustomRuleEvaluator) Evaluate(snapshot *model.SystemSnapshot, cfg *config.Config) []EvaluatedAlert
Evaluate checks user-defined AlertRules against the snapshot.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates alert evaluation, cooldown state, storage persistence, and notifications.
func (*Engine) AddCallback ¶
func (e *Engine) AddCallback(cb AlertCallback)
AddCallback registers a listener for alert events.
func (*Engine) Evaluate ¶
func (e *Engine) Evaluate(ctx context.Context, snapshot *model.SystemSnapshot) ([]model.AlertEvent, []model.AlertEvent, error)
Evaluate runs all rule evaluations against the snapshot and processes cooldowns and resolutions.
func (*Engine) GetActiveAlerts ¶
func (e *Engine) GetActiveAlerts() []model.AlertEvent
GetActiveAlerts returns currently firing alerts.
func (*Engine) RegisterRule ¶
RegisterRule adds a custom user-defined AlertRule.
type EvaluatedAlert ¶
type EvaluatedAlert struct {
RuleID string
RuleName string
MetricName string
Severity model.Severity
Triggered bool
ActualValue float64
Threshold float64
Duration time.Duration
Cooldown time.Duration
Message string
}
EvaluatedAlert represents the raw result of a rule evaluation before cooldown checks.
type RuleEvaluator ¶
type RuleEvaluator interface {
Evaluate(snapshot *model.SystemSnapshot, cfg *config.Config) []EvaluatedAlert
}
RuleEvaluator evaluates a specific metric or custom condition against a snapshot.
type StateTracker ¶
type StateTracker struct {
// contains filtered or unexported fields
}
StateTracker manages active alerts, cooldown periods, and resolution state.
func NewStateTracker ¶
func NewStateTracker() *StateTracker
NewStateTracker creates an empty alert state tracker.
func (*StateTracker) GetActiveEvents ¶
func (st *StateTracker) GetActiveEvents() []model.AlertEvent
GetActiveEvents returns all currently active alert events.
func (*StateTracker) ProcessEvaluation ¶
func (st *StateTracker) ProcessEvaluation(eval EvaluatedAlert, now time.Time) (fired *model.AlertEvent, resolved *model.AlertEvent)
ProcessEvaluation updates the internal state for an evaluated rule and returns any fired or resolved events.