Documentation ¶
Index ¶
- Variables
- func FormatFileSize(fileSize float64, unit string, unitsize float64) (size string)
- func GetConditionFactories() map[string]ConditionFactory
- func NewAlertRuleTester() models.AlertTestRunner
- func RationalizeValueFromUnit(value float64, unit string, opt string) string
- func RegisterCondition(typeName string, factory ConditionFactory)
- func RegisterNotifier(plug *NotifierPlugin)
- type AlertEngine
- type AlertRuleTester
- type Condition
- type ConditionFactory
- type ConditionResult
- type DefaultEvalHandler
- type EvalContext
- func (c *EvalContext) GetCallbackURLPrefix() string
- func (c *EvalContext) GetDurationMs() float64
- func (c *EvalContext) GetEvalMatches() []monitor.EvalMatch
- func (c *EvalContext) GetNewState() monitor.AlertStateType
- func (c *EvalContext) GetNotificationTemplateConfig() monitor.NotificationTemplateConfig
- func (c *EvalContext) GetNotificationTitle() string
- func (c *EvalContext) GetResourceNameOfMathes(matches []monitor.EvalMatch) string
- func (c *EvalContext) GetRuleTitle() string
- func (c *EvalContext) GetStateModel() *StateDescription
- func (ctx *EvalContext) ToTestRunResult() *monitor.AlertTestRunOutput
- type Job
- type NotificationConfig
- type Notifier
- type NotifierFactory
- type NotifierPlugin
- type Rule
- type RuleDescription
- type StateDescription
- type Ticker
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFrequencyCannotBeZeroOrLess frequency cannot be below zero ErrFrequencyCannotBeZeroOrLess = errors.Error(`"evaluate every" cannot be zero or below`) // ErrFrequencyCouldNotBeParsed frequency cannot be parsed ErrFrequencyCouldNotBeParsed = errors.Error(`"evaluate every" field could not be parsed`) )
Functions ¶
func FormatFileSize ¶
单位转换 保留四位小数
func GetConditionFactories ¶
func GetConditionFactories() map[string]ConditionFactory
func NewAlertRuleTester ¶
func NewAlertRuleTester() models.AlertTestRunner
func RegisterCondition ¶
func RegisterCondition(typeName string, factory ConditionFactory)
RegisterCondition adds support for alerting conditions.
func RegisterNotifier ¶
func RegisterNotifier(plug *NotifierPlugin)
Types ¶
type AlertEngine ¶
type AlertEngine struct { Scheduler scheduler // contains filtered or unexported fields }
AlertEngine is the background process that schedules alert evaluations and makes sure notifications are sent.
func (*AlertEngine) IsDisabled ¶
func (e *AlertEngine) IsDisabled() bool
IsDisabled returns true if the alerting service is disable for this instance.
type AlertRuleTester ¶
type AlertRuleTester struct{}
func (AlertRuleTester) DoTest ¶
func (_ AlertRuleTester) DoTest(ruleDef *models.SAlert, userCred mcclient.TokenCredential, input monitor.AlertTestRunInput) (*monitor.AlertTestRunOutput, error)
type Condition ¶
type Condition interface {
Eval(result *EvalContext) (*ConditionResult, error)
}
Condition is responsible for evaluating an alert condition.
type ConditionFactory ¶
type ConditionFactory func(model *monitor.AlertCondition, index int) (Condition, error)
ConditionFactory is the function signature for creating `Conditions`
type ConditionResult ¶
type ConditionResult struct { Firing bool NoDataFound bool Operator string EvalMatches []*monitor.EvalMatch AlertOkEvalMatches []*monitor.EvalMatch }
ConditionResult is the result of a condition evaluation.
type DefaultEvalHandler ¶
type DefaultEvalHandler struct {
// contains filtered or unexported fields
}
DefaultEvalHandler is responsible for evaluating the alert rule.
func NewEvalHandler ¶
func NewEvalHandler() *DefaultEvalHandler
NewEvalHandler is the `DefaultEvalHandler` constructor.
func (*DefaultEvalHandler) Eval ¶
func (e *DefaultEvalHandler) Eval(context *EvalContext)
Eval evaluated the alert rule.
type EvalContext ¶
type EvalContext struct { Firing bool IsTestRun bool IsDebug bool EvalMatches []*monitor.EvalMatch AlertOkEvalMatches []*monitor.EvalMatch Logs []*monitor.ResultLogEntry Error error ConditionEvals string StartTime time.Time EndTime time.Time Rule *Rule NoDataFound bool PrevAlertState monitor.AlertStateType Ctx context.Context UserCred mcclient.TokenCredential }
EvalContext is the context object for an alert evaluation.
func NewEvalContext ¶
func NewEvalContext(alertCtx context.Context, userCred mcclient.TokenCredential, rule *Rule) *EvalContext
NewEvalContext is the EvalContext constructor.
func (*EvalContext) GetCallbackURLPrefix ¶
func (c *EvalContext) GetCallbackURLPrefix() string
func (*EvalContext) GetDurationMs ¶
func (c *EvalContext) GetDurationMs() float64
GetDurationMs returns the duration of the alert evaluation.
func (*EvalContext) GetEvalMatches ¶
func (c *EvalContext) GetEvalMatches() []monitor.EvalMatch
func (*EvalContext) GetNewState ¶
func (c *EvalContext) GetNewState() monitor.AlertStateType
GetNewState returns the new state from the alert rule evaluation.
func (*EvalContext) GetNotificationTemplateConfig ¶
func (c *EvalContext) GetNotificationTemplateConfig() monitor.NotificationTemplateConfig
func (*EvalContext) GetNotificationTitle ¶
func (c *EvalContext) GetNotificationTitle() string
GetNotificationTitle returns the title of the alert rule including alert state.
func (*EvalContext) GetResourceNameOfMathes ¶
func (c *EvalContext) GetResourceNameOfMathes(matches []monitor.EvalMatch) string
func (*EvalContext) GetRuleTitle ¶
func (c *EvalContext) GetRuleTitle() string
func (*EvalContext) GetStateModel ¶
func (c *EvalContext) GetStateModel() *StateDescription
GetStateModel returns the `StateDescription` based on current state.
func (*EvalContext) ToTestRunResult ¶
func (ctx *EvalContext) ToTestRunResult() *monitor.AlertTestRunOutput
type Job ¶
type Job struct { Offset int64 OffsetWait bool Delay bool Rule *Rule // contains filtered or unexported fields }
Job holds state about when the alert rule should be evaluated.
func (*Job) GetRunning ¶
GetRunning returns true if the job is running. A lock is taken and released on the Job to ensure atomicity.
func (*Job) SetRunning ¶
SetRunning sets the running property on the Job. A lock is taken and released on the Job to ensure atomicity.
type NotificationConfig ¶
type NotificationConfig notifydrivers.NotificationConfig
type Notifier ¶
type Notifier interface { notifydrivers.Notifier Notify(evalContext *EvalContext, params jsonutils.JSONObject) error // ShouldNotify checks this evaluation should send an alert notification ShouldNotify(ctx context.Context, evalContext *EvalContext, notificationState *models.SAlertnotification) bool }
func InitNotifier ¶
func InitNotifier(config NotificationConfig) (Notifier, error)
InitNotifier construct a new notifier
type NotifierFactory ¶
type NotifierFactory func(config NotificationConfig) (Notifier, error)
NotifierFactory is a signature for creating notifiers
type NotifierPlugin ¶
type NotifierPlugin struct { Type string Factory NotifierFactory ValidateCreateData func(cred mcclient.IIdentityProvider, input monitor.NotificationCreateInput) (monitor.NotificationCreateInput, error) }
type Rule ¶
type Rule struct { Id string Frequency int64 Title string Name string Message string LastStateChange time.Time For time.Duration NoDataState monitor.NoDataOption ExecutionErrorState monitor.ExecutionErrorOption State monitor.AlertStateType Conditions []Condition Notifications []string // AlertRuleTags []*models.AlertRuleTag Level string RuleDescription []*RuleDescription StateChanges int CustomizeConfig jsonutils.JSONObject // 静默期 SilentPeriod int64 }
Rule is the in-memory version of an alert rule.
type RuleDescription ¶
type RuleDescription struct {
monitor.AlertRecordRule
}
type StateDescription ¶
SateDescription contains visual information about the alert state.
type Ticker ¶
Ticker is a ticker to power the alerting scheduler. it's like a time.Ticker, except:
- it doesn't drop ticks for slow receivers, rather, it queues up. so that callers are in control to instrument what's going on.
- it automatically ticks every second, which is the right thing in our current design
- it ticks on second marks or very shortly after. this provides a predictable load pattern (this shouldn't cause too much load contention issues because the next steps in the pipeline just process at their own pace)
- the timestamps are used to mark "last datapoint to query for" and as such, are a configurable amount of seconds in the past
- because we want to allow:
- a clean "resume where we left off" and "don't yield ticks we already did"
- adjusting offset over time to compensate for storage backing up or getting fast and providing lower latency you specify a lastProcessed timestamp as well as an offset at creation, or runtime