Documentation ¶
Index ¶
- type Alert
- type AlertState
- type AlertingRule
- func (r *AlertingRule) ActiveAlerts() []*Alert
- func (r *AlertingRule) Annotations() labels.Labels
- func (r *AlertingRule) Duration() time.Duration
- func (r *AlertingRule) Eval(ctx context.Context, ts time.Time, query QueryFunc, externalURL *url.URL) (promql.Vector, error)
- func (r *AlertingRule) ForEachActiveAlert(f func(*Alert))
- func (r *AlertingRule) GetEvaluationDuration() time.Duration
- func (r *AlertingRule) GetEvaluationTimestamp() time.Time
- func (r *AlertingRule) HTMLSnippet(pathPrefix string) html_template.HTML
- func (r *AlertingRule) Health() RuleHealth
- func (r *AlertingRule) HoldDuration() time.Duration
- func (r *AlertingRule) Labels() labels.Labels
- func (r *AlertingRule) LastError() error
- func (r *AlertingRule) Name() string
- func (r *AlertingRule) Query() promql.Expr
- func (r *AlertingRule) SetEvaluationDuration(dur time.Duration)
- func (r *AlertingRule) SetEvaluationTimestamp(ts time.Time)
- func (r *AlertingRule) SetHealth(health RuleHealth)
- func (r *AlertingRule) SetLastError(err error)
- func (r *AlertingRule) SetRestored(restored bool)
- func (r *AlertingRule) State() AlertState
- func (r *AlertingRule) String() string
- type Appendable
- type Group
- func (g *Group) AlertingRules() []*AlertingRule
- func (g *Group) CopyState(from *Group)
- func (g *Group) Eval(ctx context.Context, ts time.Time)
- func (g *Group) File() string
- func (g *Group) GetEvaluationDuration() time.Duration
- func (g *Group) GetEvaluationTimestamp() time.Time
- func (g *Group) HasAlertingRules() bool
- func (g *Group) Interval() time.Duration
- func (g *Group) Name() string
- func (g *Group) RestoreForState(ts time.Time)
- func (g *Group) Rules() []Rule
- type Manager
- func (m *Manager) AlertingRules() []*AlertingRule
- func (m *Manager) Collect(ch chan<- prometheus.Metric)
- func (m *Manager) Describe(ch chan<- *prometheus.Desc)
- func (m *Manager) LoadGroups(interval time.Duration, externalLabels labels.Labels, filenames ...string) (map[string]*Group, []error)
- func (m *Manager) RuleGroups() []*Group
- func (m *Manager) Rules() []Rule
- func (m *Manager) Run()
- func (m *Manager) Stop()
- func (m *Manager) Update(interval time.Duration, files []string, externalLabels labels.Labels) error
- type ManagerOptions
- type Metrics
- type NotifyFunc
- type QueryFunc
- type RecordingRule
- func (rule *RecordingRule) Eval(ctx context.Context, ts time.Time, query QueryFunc, _ *url.URL) (promql.Vector, error)
- func (rule *RecordingRule) GetEvaluationDuration() time.Duration
- func (rule *RecordingRule) GetEvaluationTimestamp() time.Time
- func (rule *RecordingRule) HTMLSnippet(pathPrefix string) template.HTML
- func (rule *RecordingRule) Health() RuleHealth
- func (rule *RecordingRule) Labels() labels.Labels
- func (rule *RecordingRule) LastError() error
- func (rule *RecordingRule) Name() string
- func (rule *RecordingRule) Query() promql.Expr
- func (rule *RecordingRule) SetEvaluationDuration(dur time.Duration)
- func (rule *RecordingRule) SetEvaluationTimestamp(ts time.Time)
- func (rule *RecordingRule) SetHealth(health RuleHealth)
- func (rule *RecordingRule) SetLastError(err error)
- func (rule *RecordingRule) String() string
- type Rule
- type RuleHealth
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct { State AlertState Labels labels.Labels Annotations labels.Labels // The value at the last evaluation of the alerting expression. Value float64 // The interval during which the condition of this alert held true. // ResolvedAt will be 0 to indicate a still active alert. ActiveAt time.Time FiredAt time.Time ResolvedAt time.Time LastSentAt time.Time ValidUntil time.Time }
Alert is the user-level representation of a single instance of an alerting rule.
type AlertState ¶
type AlertState int
AlertState denotes the state of an active alert.
const ( // StateInactive is the state of an alert that is neither firing nor pending. StateInactive AlertState = iota // StatePending is the state of an alert that has been active for less than // the configured threshold duration. StatePending // StateFiring is the state of an alert that has been active for longer than // the configured threshold duration. StateFiring )
func (AlertState) String ¶
func (s AlertState) String() string
type AlertingRule ¶
type AlertingRule struct {
// contains filtered or unexported fields
}
An AlertingRule generates alerts from its vector expression.
func NewAlertingRule ¶
func NewAlertingRule( name string, vec promql.Expr, hold time.Duration, labels, annotations, externalLabels labels.Labels, restored bool, logger log.Logger, ) *AlertingRule
NewAlertingRule constructs a new AlertingRule.
func (*AlertingRule) ActiveAlerts ¶
func (r *AlertingRule) ActiveAlerts() []*Alert
ActiveAlerts returns a slice of active alerts.
func (*AlertingRule) Annotations ¶
func (r *AlertingRule) Annotations() labels.Labels
Annotations returns the annotations of the alerting rule.
func (*AlertingRule) Duration ¶
func (r *AlertingRule) Duration() time.Duration
Duration returns the hold duration of the alerting rule.
func (*AlertingRule) Eval ¶
func (r *AlertingRule) Eval(ctx context.Context, ts time.Time, query QueryFunc, externalURL *url.URL) (promql.Vector, error)
Eval evaluates the rule expression and then creates pending alerts and fires or removes previously pending alerts accordingly.
func (*AlertingRule) ForEachActiveAlert ¶
func (r *AlertingRule) ForEachActiveAlert(f func(*Alert))
ForEachActiveAlert runs the given function on each alert. This should be used when you want to use the actual alerts from the AlertingRule and not on its copy. If you want to run on a copy of alerts then don't use this, get the alerts from 'ActiveAlerts()'.
func (*AlertingRule) GetEvaluationDuration ¶
func (r *AlertingRule) GetEvaluationDuration() time.Duration
GetEvaluationDuration returns the time in seconds it took to evaluate the alerting rule.
func (*AlertingRule) GetEvaluationTimestamp ¶
func (r *AlertingRule) GetEvaluationTimestamp() time.Time
GetEvaluationTimestamp returns the time the evaluation took place.
func (*AlertingRule) HTMLSnippet ¶
func (r *AlertingRule) HTMLSnippet(pathPrefix string) html_template.HTML
HTMLSnippet returns an HTML snippet representing this alerting rule. The resulting snippet is expected to be presented in a <pre> element, so that line breaks and other returned whitespace is respected.
func (*AlertingRule) Health ¶
func (r *AlertingRule) Health() RuleHealth
Health returns the current health of the alerting rule.
func (*AlertingRule) HoldDuration ¶
func (r *AlertingRule) HoldDuration() time.Duration
HoldDuration returns the holdDuration of the alerting rule.
func (*AlertingRule) Labels ¶
func (r *AlertingRule) Labels() labels.Labels
Labels returns the labels of the alerting rule.
func (*AlertingRule) LastError ¶
func (r *AlertingRule) LastError() error
LastError returns the last error seen by the alerting rule.
func (*AlertingRule) Name ¶
func (r *AlertingRule) Name() string
Name returns the name of the alerting rule.
func (*AlertingRule) Query ¶
func (r *AlertingRule) Query() promql.Expr
Query returns the query expression of the alerting rule.
func (*AlertingRule) SetEvaluationDuration ¶
func (r *AlertingRule) SetEvaluationDuration(dur time.Duration)
SetEvaluationDuration updates evaluationDuration to the duration it took to evaluate the rule on its last evaluation.
func (*AlertingRule) SetEvaluationTimestamp ¶
func (r *AlertingRule) SetEvaluationTimestamp(ts time.Time)
SetEvaluationTimestamp updates evaluationTimestamp to the timestamp of when the rule was last evaluated.
func (*AlertingRule) SetHealth ¶
func (r *AlertingRule) SetHealth(health RuleHealth)
SetHealth sets the current health of the alerting rule.
func (*AlertingRule) SetLastError ¶
func (r *AlertingRule) SetLastError(err error)
SetLastError sets the current error seen by the alerting rule.
func (*AlertingRule) SetRestored ¶
func (r *AlertingRule) SetRestored(restored bool)
SetRestored updates the restoration state of the alerting rule.
func (*AlertingRule) State ¶
func (r *AlertingRule) State() AlertState
State returns the maximum state of alert instances for this rule. StateFiring > StatePending > StateInactive
func (*AlertingRule) String ¶
func (r *AlertingRule) String() string
type Appendable ¶
Appendable returns an Appender.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a set of rules that have a logical relation.
func NewGroup ¶
func NewGroup(name, file string, interval time.Duration, rules []Rule, shouldRestore bool, opts *ManagerOptions) *Group
NewGroup makes a new Group with the given name, options, and rules.
func (*Group) AlertingRules ¶
func (g *Group) AlertingRules() []*AlertingRule
AlertingRules returns the list of the group's alerting rules.
func (*Group) CopyState ¶
CopyState copies the alerting rule and staleness related state from the given group.
Rules are matched based on their name and labels. If there are duplicates, the first is matched with the first, second with the second etc.
func (*Group) Eval ¶
Eval runs a single evaluation cycle in which all rules are evaluated sequentially.
func (*Group) GetEvaluationDuration ¶
GetEvaluationDuration returns the time in seconds it took to evaluate the rule group.
func (*Group) GetEvaluationTimestamp ¶
GetEvaluationTimestamp returns the time the last evaluation of the rule group took place.
func (*Group) HasAlertingRules ¶
HasAlertingRules returns true if the group contains at least one AlertingRule.
func (*Group) RestoreForState ¶
RestoreForState restores the 'for' state of the alerts by looking up last ActiveAt from storage.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
The Manager manages recording and alerting rules.
func NewManager ¶
func NewManager(o *ManagerOptions) *Manager
NewManager returns an implementation of Manager, ready to be started by calling the Run method.
func (*Manager) AlertingRules ¶
func (m *Manager) AlertingRules() []*AlertingRule
AlertingRules returns the list of the manager's alerting rules.
func (*Manager) Collect ¶
func (m *Manager) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (*Manager) Describe ¶
func (m *Manager) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
func (*Manager) LoadGroups ¶
func (m *Manager) LoadGroups( interval time.Duration, externalLabels labels.Labels, filenames ...string, ) (map[string]*Group, []error)
LoadGroups reads groups from a list of files.
func (*Manager) RuleGroups ¶
RuleGroups returns the list of manager's rule groups.
type ManagerOptions ¶
type ManagerOptions struct { ExternalURL *url.URL QueryFunc QueryFunc NotifyFunc NotifyFunc Context context.Context Appendable Appendable TSDB storage.Storage Logger log.Logger Registerer prometheus.Registerer OutageTolerance time.Duration ForGracePeriod time.Duration ResendDelay time.Duration Metrics *Metrics }
ManagerOptions bundles options for the Manager.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics for rule evaluation.
func NewGroupMetrics ¶
func NewGroupMetrics(reg prometheus.Registerer) *Metrics
NewGroupMetrics makes a new Metrics and registers them with the provided registerer, if not nil.
type NotifyFunc ¶
NotifyFunc sends notifications about a set of alerts generated by the given expression.
type RecordingRule ¶
type RecordingRule struct {
// contains filtered or unexported fields
}
A RecordingRule records its vector expression into new timeseries.
func NewRecordingRule ¶
NewRecordingRule returns a new recording rule.
func (*RecordingRule) Eval ¶
func (rule *RecordingRule) Eval(ctx context.Context, ts time.Time, query QueryFunc, _ *url.URL) (promql.Vector, error)
Eval evaluates the rule and then overrides the metric names and labels accordingly.
func (*RecordingRule) GetEvaluationDuration ¶
func (rule *RecordingRule) GetEvaluationDuration() time.Duration
GetEvaluationDuration returns the time in seconds it took to evaluate the recording rule.
func (*RecordingRule) GetEvaluationTimestamp ¶
func (rule *RecordingRule) GetEvaluationTimestamp() time.Time
GetEvaluationTimestamp returns the time the evaluation took place.
func (*RecordingRule) HTMLSnippet ¶
func (rule *RecordingRule) HTMLSnippet(pathPrefix string) template.HTML
HTMLSnippet returns an HTML snippet representing this rule.
func (*RecordingRule) Health ¶
func (rule *RecordingRule) Health() RuleHealth
Health returns the current health of the recording rule.
func (*RecordingRule) Labels ¶
func (rule *RecordingRule) Labels() labels.Labels
Labels returns the rule labels.
func (*RecordingRule) LastError ¶
func (rule *RecordingRule) LastError() error
LastError returns the last error seen by the recording rule.
func (*RecordingRule) Query ¶
func (rule *RecordingRule) Query() promql.Expr
Query returns the rule query expression.
func (*RecordingRule) SetEvaluationDuration ¶
func (rule *RecordingRule) SetEvaluationDuration(dur time.Duration)
SetEvaluationDuration updates evaluationDuration to the time in seconds it took to evaluate the rule on its last evaluation.
func (*RecordingRule) SetEvaluationTimestamp ¶
func (rule *RecordingRule) SetEvaluationTimestamp(ts time.Time)
SetEvaluationTimestamp updates evaluationTimestamp to the timestamp of when the rule was last evaluated.
func (*RecordingRule) SetHealth ¶
func (rule *RecordingRule) SetHealth(health RuleHealth)
SetHealth sets the current health of the recording rule.
func (*RecordingRule) SetLastError ¶
func (rule *RecordingRule) SetLastError(err error)
SetLastError sets the current error seen by the recording rule.
func (*RecordingRule) String ¶
func (rule *RecordingRule) String() string
type Rule ¶
type Rule interface { Name() string // Labels of the rule. Labels() labels.Labels // eval evaluates the rule, including any associated recording or alerting actions. Eval(context.Context, time.Time, QueryFunc, *url.URL) (promql.Vector, error) // String returns a human-readable string representation of the rule. String() string // SetLastErr sets the current error experienced by the rule. SetLastError(error) // LastErr returns the last error experienced by the rule. LastError() error // SetHealth sets the current health of the rule. SetHealth(RuleHealth) // Health returns the current health of the rule. Health() RuleHealth SetEvaluationDuration(time.Duration) // GetEvaluationDuration returns last evaluation duration. // NOTE: Used dynamically by rules.html template. GetEvaluationDuration() time.Duration SetEvaluationTimestamp(time.Time) // GetEvaluationTimestamp returns last evaluation timestamp. // NOTE: Used dynamically by rules.html template. GetEvaluationTimestamp() time.Time // HTMLSnippet returns a human-readable string representation of the rule, // decorated with HTML elements for use the web frontend. HTMLSnippet(pathPrefix string) html_template.HTML }
A Rule encapsulates a vector expression which is evaluated at a specified interval and acted upon (currently either recorded or used for alerting).
type RuleHealth ¶
type RuleHealth string
RuleHealth describes the health state of a rule.
const ( HealthUnknown RuleHealth = "unknown" HealthGood RuleHealth = "ok" HealthBad RuleHealth = "err" )
The possible health states of a rule based on the last execution.