rules

package
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

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
}

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, lbls, anns labels.Labels, 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) 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) GetEvaluationTime

func (r *AlertingRule) GetEvaluationTime() time.Duration

GetEvaluationTime returns the time in seconds it took to evaluate the alerting rule.

func (*AlertingRule) HTMLSnippet added in v1.0.0

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) Name

func (r *AlertingRule) Name() string

Name returns the name of the alert.

func (*AlertingRule) SetEvaluationTime

func (r *AlertingRule) SetEvaluationTime(dur time.Duration)

SetEvaluationTime updates evaluationTime to the duration it took to evaluate the rule on its last evaluation.

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

type Appendable interface {
	Appender() (storage.Appender, error)
}

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, opts *ManagerOptions) *Group

NewGroup makes a new Group with the given name, options, and rules.

func (*Group) Eval

func (g *Group) Eval(ctx context.Context, ts time.Time)

Eval runs a single evaluation cycle in which all rules are evaluated sequentially.

func (*Group) File

func (g *Group) File() string

File returns the group's file.

func (*Group) GetEvaluationTime

func (g *Group) GetEvaluationTime() time.Duration

GetEvaluationTime returns the time in seconds it took to evaluate the rule group.

func (*Group) Name

func (g *Group) Name() string

Name returns the group name.

func (*Group) Rules

func (g *Group) Rules() []Rule

Rules returns the group's rules.

func (*Group) SetEvaluationTime

func (g *Group) SetEvaluationTime(dur time.Duration)

SetEvaluationTime sets the time in seconds the last evaluation took.

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) RuleGroups

func (m *Manager) RuleGroups() []*Group

RuleGroups returns the list of manager's rule groups.

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 starts processing of the rule manager.

func (*Manager) Stop

func (m *Manager) Stop()

Stop the rule manager's rule evaluation cycles.

func (*Manager) Update

func (m *Manager) Update(interval time.Duration, files []string) error

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

type ManagerOptions

type ManagerOptions struct {
	ExternalURL *url.URL
	QueryFunc   QueryFunc
	NotifyFunc  NotifyFunc
	Context     context.Context
	Appendable  Appendable
	Logger      log.Logger
	Registerer  prometheus.Registerer
}

ManagerOptions bundles options for the Manager.

type NotifyFunc

type NotifyFunc func(ctx context.Context, expr string, alerts ...*Alert) error

NotifyFunc sends notifications about a set of alerts generated by the given expression.

type QueryFunc

type QueryFunc func(ctx context.Context, q string, t time.Time) (promql.Vector, error)

QueryFunc processes PromQL queries.

func EngineQueryFunc

func EngineQueryFunc(engine *promql.Engine, q storage.Queryable) QueryFunc

EngineQueryFunc returns a new query function that executes instant queries against the given engine. It converts scaler into vector results.

type RecordingRule

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

A RecordingRule records its vector expression into new timeseries.

func NewRecordingRule

func NewRecordingRule(name string, vector promql.Expr, lset labels.Labels) *RecordingRule

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) GetEvaluationTime

func (rule *RecordingRule) GetEvaluationTime() time.Duration

GetEvaluationTime returns the time in seconds it took to evaluate the recording rule.

func (*RecordingRule) HTMLSnippet added in v1.0.0

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) SetEvaluationTime

func (rule *RecordingRule) SetEvaluationTime(dur time.Duration)

SetEvaluationTime updates evaluationTimeSeconds to the time in seconds it took to evaluate the rule on its last evaluation.

func (*RecordingRule) String

func (rule *RecordingRule) String() string

type Rule

type Rule interface {
	Name() string
	// 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

	SetEvaluationTime(time.Duration)
	GetEvaluationTime() time.Duration
	// 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).

Jump to

Keyboard shortcuts

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