alert

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const JITTER_FACTOR = 7000

7 seconds jitter factor for evaluation among different rules

Variables

This section is empty.

Functions

func SendAlert

func SendAlert(ctx context.Context, alertManagerURL string, alerts []PostableAlert) error

Types

type Alert

type Alert struct {
	Labels       LabelSet `json:"labels"`
	GeneratorURL string   `json:"generatorURL,omitempty"`
}

type AlertEvaluator

type AlertEvaluator struct {
	DB    *metrics.TimeSeriesDB
	Rules []Rule
	// contains filtered or unexported fields
}

AlertEvaluator send new or resolved alerts to alertmanager use alertmanager to implement deduplication, notification it connect TSDB, evaluate all rules to with its own interval for each rule, the query result should contains fields that can be compared with threshold, and other fields which are used to generate alert labelSet and description The query and description can use Go templates with the rule data and query results

func NewAlertEvaluator

func NewAlertEvaluator(ctx context.Context, db *metrics.TimeSeriesDB, rules []Rule, alertManagerURL string) *AlertEvaluator

func (*AlertEvaluator) StartEvaluate

func (e *AlertEvaluator) StartEvaluate() error

func (*AlertEvaluator) StopEvaluate

func (e *AlertEvaluator) StopEvaluate() error

func (*AlertEvaluator) UpdateAlertRules

func (e *AlertEvaluator) UpdateAlertRules(rules []Rule) error

type AlertStatus

type AlertStatus struct {
	State       string   `json:"state"`
	SilencedBy  []string `json:"silencedBy"`
	InhibitedBy []string `json:"inhibitedBy"`
	MutedBy     []string `json:"mutedBy"`
}

type GettableAlert

type GettableAlert struct {
	Alert
	Annotations LabelSet    `json:"annotations"`
	Receivers   []Receiver  `json:"receivers"`
	Fingerprint string      `json:"fingerprint"`
	StartsAt    time.Time   `json:"startsAt"`
	UpdatedAt   time.Time   `json:"updatedAt"`
	EndsAt      time.Time   `json:"endsAt"`
	Status      AlertStatus `json:"status"`
}

type LabelSet

type LabelSet map[string]string

type Matcher

type Matcher struct {
	Name    string `json:"name"`
	Value   string `json:"value"`
	IsRegex bool   `json:"isRegex"`
	IsEqual bool   `json:"isEqual,omitempty"`
}

type PostableAlert

type PostableAlert struct {
	Alert
	StartsAt    time.Time `json:"startsAt,omitempty"`
	EndsAt      time.Time `json:"endsAt,omitempty"`
	Annotations LabelSet  `json:"annotations,omitempty"`
}

func CreateAlertData

func CreateAlertData(name, summary, description string, labels LabelSet, annotations LabelSet, startsAt time.Time) PostableAlert

type Receiver

type Receiver struct {
	Name string `json:"name"`
}

type Rule

type Rule struct {
	Name                string  `yaml:"name"`
	Query               string  `yaml:"query"`
	Threshold           float64 `yaml:"threshold"`
	EvaluationInterval  string  `yaml:"evaluationInterval"`
	ConsecutiveCount    int     `yaml:"consecutiveCount"`
	Severity            string  `yaml:"severity"`
	Summary             string  `yaml:"summary"`
	Description         string  `yaml:"description"`
	RunBookURL          string  `yaml:"runbookURL"`
	AlertTargetInstance string  `yaml:"alertTargetInstance"`
	// contains filtered or unexported fields
}

func (*Rule) AddFiringAlertAndCheckResolved

func (r *Rule) AddFiringAlertAndCheckResolved(alertQueryResult map[string]interface{}) (*PostableAlert, bool, string)

func (*Rule) CheckAndRemoveFiringAlerts

func (r *Rule) CheckAndRemoveFiringAlerts(firingAlertSet map[string]struct{}) []PostableAlert

func (*Rule) IsTestMode

func (r *Rule) IsTestMode() bool

func (*Rule) String

func (r *Rule) String() string

Jump to

Keyboard shortcuts

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