rules

package
v0.0.0-...-f2052c9 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2014 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Copyright 2013 Prometheus Team * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

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"
)
View Source
const ADDITIVE_OP = 57358
View Source
const AGGR_OP = 57356
View Source
const ALERT = 57360
View Source
const CMP_OP = 57357
View Source
const DESCRIPTION = 57365
View Source
const DURATION = 57350
View Source
const FOR = 57362
View Source
const GROUP_OP = 57354
View Source
const IDENTIFIER = 57348
View Source
const IF = 57361
View Source
const KEEPING_EXTRA = 57355
View Source
const METRICNAME = 57351
View Source
const MULT_OP = 57359
View Source
const NUMBER = 57352
View Source
const PERMANENT = 57353
View Source
const START_EXPRESSION = 57347
View Source
const START_RULES = 57346
View Source
const STRING = 57349
View Source
const SUMMARY = 57364
View Source
const WITH = 57363

Variables

This section is empty.

Functions

func GraphLinkForExpression

func GraphLinkForExpression(expr string) string

GraphLinkForExpression creates an escaped relative link to the graph view of the provided expression.

func LoadExprFromFile

func LoadExprFromFile(fileName string) (ast.Node, error)

LoadExprFromFile parses a single expression from the file of the provided name and returns it as an AST node.

func LoadExprFromReader

func LoadExprFromReader(exprReader io.Reader) (ast.Node, error)

LoadExprFromReader parses a single expression from the provided reader and returns it as an AST node.

func LoadExprFromString

func LoadExprFromString(exprString string) (ast.Node, error)

LoadExprFromString parses a single expression from the provided string and returns it as an AST node.

func NewArithExpr

func NewArithExpr(opTypeStr string, lhs ast.Node, rhs ast.Node) (ast.Node, error)

NewArithExpr is a convenience function to create a new AST arithmetic expression.

func NewFunctionCall

func NewFunctionCall(name string, args []ast.Node) (ast.Node, error)

NewFunctionCall is a convenience function to create a new AST function-call node.

func NewMatrixSelector

func NewMatrixSelector(vector ast.Node, intervalStr string) (ast.MatrixNode, error)

NewMatrixSelector is a convenience function to create a new AST matrix selector.

func NewVectorAggregation

func NewVectorAggregation(aggrTypeStr string, vector ast.Node, groupBy clientmodel.LabelNames, keepExtraLabels bool) (*ast.VectorAggregation, error)

NewVectorAggregation is a convenience function to create a new AST vector aggregation.

func TableLinkForExpression

func TableLinkForExpression(expr string) string

TableLinkForExpression creates an escaped relative link to the table view of the provided expression.

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 ast.VectorNode

	// 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 CreateAlertingRule

func CreateAlertingRule(name string, expr ast.Node, holdDurationStr string, labels clientmodel.LabelSet, summary string, description string) (*AlertingRule, error)

CreateAlertingRule is a convenience function to create a new alerting rule.

func NewAlertingRule

func NewAlertingRule(name string, vector ast.VectorNode, 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) Eval

func (rule *AlertingRule) Eval(timestamp clientmodel.Timestamp, storage local.Storage) (ast.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, storage local.Storage) (ast.Vector, error)

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

func (*AlertingRule) HTMLSnippet

func (rule *AlertingRule) HTMLSnippet() 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

func (*AlertingRule) ToDotGraph

func (rule *AlertingRule) ToDotGraph() string

ToDotGraph returns the text representation of a dot graph.

type RecordingRule

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

A RecordingRule records its vector expression into new timeseries.

func CreateRecordingRule

func CreateRecordingRule(name string, labels clientmodel.LabelSet, expr ast.Node, permanent bool) (*RecordingRule, error)

CreateRecordingRule is a convenience function to create a recording rule.

func (RecordingRule) Eval

func (rule RecordingRule) Eval(timestamp clientmodel.Timestamp, storage local.Storage) (ast.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, storage local.Storage) (ast.Vector, error)

EvalRaw returns the raw value of the rule expression.

func (RecordingRule) HTMLSnippet

func (rule RecordingRule) HTMLSnippet() 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

func (RecordingRule) ToDotGraph

func (rule RecordingRule) ToDotGraph() string

ToDotGraph returns the text representation of a dot graph.

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(timestamp clientmodel.Timestamp, storage local.Storage) (ast.Vector, error)
	// Eval evaluates the rule, including any associated recording or alerting actions.
	Eval(timestamp clientmodel.Timestamp, storage local.Storage) (ast.Vector, error)
	// ToDotGraph returns a Graphviz dot graph of the rule.
	ToDotGraph() 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() 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).

func LoadRulesFromFile

func LoadRulesFromFile(fileName string) ([]Rule, error)

LoadRulesFromFile parses rules from the file of the provided name and returns them.

func LoadRulesFromReader

func LoadRulesFromReader(rulesReader io.Reader) ([]Rule, error)

LoadRulesFromReader parses rules from the provided reader and returns them.

func LoadRulesFromString

func LoadRulesFromString(rulesString string) ([]Rule, error)

LoadRulesFromString parses rules from the provided string returns them.

type RulesLexer

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

RulesLexer is the lexer for rule expressions.

func (*RulesLexer) Error

func (lexer *RulesLexer) Error(errorStr string)

func (*RulesLexer) Lex

func (lexer *RulesLexer) Lex(lval *yySymType) int

Lex is called by the parser generated by "go tool yacc" to obtain each token. The method is opened before the matching rules block and closed at the end of the file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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