rules

package
v0.0.0-...-d0f20ad Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AlertMetricName is the metric name for synthetic alert timeseries.
	AlertMetricName clientmodel.LabelValue = "ALERTS"

	// AlertNameLabel is the label name indicating the name of an alert.
	AlertNameLabel clientmodel.LabelName = "alertname"
	// AlertStateLabel is the label name indicating the state of an alert.
	AlertStateLabel clientmodel.LabelName = "alertstate"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	// The name of the alert.
	Name string
	// The vector element labelset triggering this alert.
	Labels clientmodel.LabelSet
	// The state of the alert (Pending or Firing).
	State AlertState
	// The time when the alert first transitioned into Pending state.
	ActiveSince clientmodel.Timestamp
	// The value of the alert expression for this vector element.
	Value clientmodel.SampleValue
}

Alert is used to track active (pending/firing) alerts over time.

type AlertState

type AlertState int

AlertState denotes the state of an active alert.

const (
	// Inactive alerts are neither firing nor pending.
	Inactive AlertState = iota
	// Pending alerts have been active for less than the configured
	// threshold duration.
	Pending
	// Firing alerts have been active for longer than the configured
	// threshold duration.
	Firing
)

func (AlertState) String

func (s AlertState) String() string

type AlertingRule

type AlertingRule struct {

	// The vector expression from which to generate alerts.
	Vector promql.Expr

	// Extra labels to attach to the resulting alert sample vectors.
	Labels clientmodel.LabelSet
	// Short alert summary, suitable for email subjects.
	Summary string
	// More detailed alert description.
	Description string
	// contains filtered or unexported fields
}

An AlertingRule generates alerts from its vector expression.

func NewAlertingRule

func NewAlertingRule(name string, vector promql.Expr, holdDuration time.Duration, labels clientmodel.LabelSet, summary string, description string) *AlertingRule

NewAlertingRule constructs a new AlertingRule.

func (*AlertingRule) ActiveAlerts

func (rule *AlertingRule) ActiveAlerts() []Alert

ActiveAlerts returns a slice of active alerts.

func (*AlertingRule) DotGraph

func (rule *AlertingRule) DotGraph() string

DotGraph returns the text representation of a dot graph.

func (*AlertingRule) Eval

func (rule *AlertingRule) Eval(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error)

Eval evaluates the rule expression and then creates pending alerts and fires or removes previously pending alerts accordingly.

func (*AlertingRule) EvalRaw

func (rule *AlertingRule) EvalRaw(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error)

EvalRaw returns the raw value of the rule expression, without creating alerts.

func (*AlertingRule) HTMLSnippet

func (rule *AlertingRule) HTMLSnippet(pathPrefix string) template.HTML

HTMLSnippet returns an HTML snippet representing this alerting rule.

func (*AlertingRule) Name

func (rule *AlertingRule) Name() string

Name returns the name of the alert.

func (*AlertingRule) State

func (rule *AlertingRule) State() AlertState

State returns the "maximum" state: firing > pending > inactive.

func (*AlertingRule) String

func (rule *AlertingRule) String() string

type Manager

type Manager struct {
	// Protects the rules list.
	sync.Mutex
	// 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) ApplyConfig

func (m *Manager) ApplyConfig(conf *config.Config)

ApplyConfig updates the rule manager's state as the config requires. If loading the new rules failed the old rule set is restored.

func (*Manager) Rules

func (m *Manager) Rules() []Rule

Rules returns the list of the manager's rules.

func (*Manager) Run

func (m *Manager) Run()

Run the rule manager's periodic rule evaluation.

func (*Manager) Stop

func (m *Manager) Stop()

Stop the rule manager's rule evaluation cycles.

type ManagerOptions

type ManagerOptions struct {
	EvaluationInterval time.Duration
	QueryEngine        *promql.Engine

	NotificationHandler *notification.NotificationHandler
	SampleAppender      storage.SampleAppender

	PrometheusURL string
	PathPrefix    string
}

ManagerOptions bundles options for the Manager.

type RecordingRule

type RecordingRule struct {
	// contains filtered or unexported fields
}

A RecordingRule records its vector expression into new timeseries.

func (RecordingRule) DotGraph

func (rule RecordingRule) DotGraph() string

DotGraph returns the text representation of a dot graph.

func (RecordingRule) Eval

func (rule RecordingRule) Eval(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error)

Eval evaluates the rule and then overrides the metric names and labels accordingly.

func (RecordingRule) EvalRaw

func (rule RecordingRule) EvalRaw(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error)

EvalRaw returns the raw value of the rule expression.

func (RecordingRule) HTMLSnippet

func (rule RecordingRule) HTMLSnippet(pathPrefix string) template.HTML

HTMLSnippet returns an HTML snippet representing this rule.

func (RecordingRule) Name

func (rule RecordingRule) Name() string

Name returns the rule name.

func (RecordingRule) String

func (rule RecordingRule) String() string

type Rule

type Rule interface {
	// Name returns the name of the rule.
	Name() string
	// EvalRaw evaluates the rule's vector expression without triggering any
	// other actions, like recording or alerting.
	EvalRaw(clientmodel.Timestamp, *promql.Engine) (promql.Vector, error)
	// Eval evaluates the rule, including any associated recording or alerting actions.
	Eval(clientmodel.Timestamp, *promql.Engine) (promql.Vector, error)
	// DotGraph returns a Graphviz dot graph of the rule.
	DotGraph() string
	// String returns a human-readable string representation of the rule.
	String() string
	// HTMLSnippet returns a human-readable string representation of the rule,
	// decorated with HTML elements for use the web frontend.
	HTMLSnippet(pathPrefix string) 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).

Notes

Bugs

  • Look at fixing thundering herd.

Jump to

Keyboard shortcuts

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