kapacitor

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Prefix is prepended to the ID of all alerts
	Prefix = "chronograf-v1-"

	// FetchRate is the rate Paginating Kapacitor Clients will consume responses
	FetchRate = 100
)
View Source
const (
	// Deadman triggers when data is missing for a period of time
	Deadman = "deadman"
	// Relative triggers when the value has changed compared to the past
	Relative = "relative"
	// Threshold triggers when value crosses a threshold
	Threshold = "threshold"
	// ThresholdRange triggers when a value is inside or outside a range
	ThresholdRange = "range"
	// ChangePercent triggers a relative alert when value changed by a percentage
	ChangePercent = "% change"
	// ChangeAmount triggers a relative alert when the value change by some amount
	ChangeAmount = "change"
)
View Source
const ErrNotChronoTickscript = Error("TICKscript not built with chronograf builder")

ErrNotChronoTickscript signals a TICKscript that cannot be parsed into chronograf data structure.

View Source
const HTTPEndpoint = "output"

HTTPEndpoint is the default location of the tickscript output

View Source
const (
	// ListTaskWorkers describes the number of workers concurrently fetching
	// tasks from Kapacitor. This constant was chosen after some benchmarking
	// work and should likely work well for quad-core systems
	ListTaskWorkers = 4
)

Variables

View Source
var (
	// Database is the output database for alerts.
	Database = "chronograf"
	// RP will be autogen for alerts because it is default.
	RP = "autogen"
	// Measurement will be alerts so that the app knows where to get this data.
	Measurement = "alerts"
	// IDTag is the output tag key for the ID of the alert
	IDTag = "alertID"
	//LevelTag is the output tag key for the alert level information
	LevelTag = "level"
	// MessageField is the output field key for the message in the alert
	MessageField = "message"
	// DurationField is the output field key for the duration of the alert
	DurationField = "duration"
)
View Source
var AllAlerts = `` /* 131-byte string literal not displayed */

AllAlerts are properties all alert types will have

View Source
var DeadmanTrigger = `
  var trigger = data|deadman(threshold, period)
`

DeadmanTrigger checks if any data has been streamed in the last period of time

View Source
var Details = `
	.details(details)
`

Details is used only for alerts that specify detail string

View Source
var RelativeAbsoluteTrigger = `` /* 244-byte string literal not displayed */

RelativeAbsoluteTrigger compares one window of data versus another (current - past)

View Source
var RelativePercentTrigger = `` /* 277-byte string literal not displayed */

RelativePercentTrigger compares one window of data versus another as a percent change.

View Source
var ThresholdRangeTrigger = `
	var trigger = data
	|alert()
		.crit(lambda: "value" %s lower %s "value" %s upper)
`

ThresholdRangeTrigger is the alert when data does not intersect the range.

View Source
var ThresholdTrigger = `
  var trigger = data
  |alert()
    .crit(lambda: "value" %s crit)
`

ThresholdTrigger is the tickscript trigger for alerts that exceed a value

Functions

func AlertServices

func AlertServices(rule chronograf.AlertRule) (string, error)

AlertServices generates alert chaining methods to be attached to an alert from all rule Services

func Data

func Data(rule chronograf.AlertRule) (string, error)

Data returns the tickscript data section for querying

func Escape

func Escape(str string) string

Escape sanitizes strings with single quotes for kapacitor

func GetAlertRuleName added in v1.9.4

func GetAlertRuleName(task *client.Task) string

GetAlertRuleName returns chronograf rule name out of kapacitor task. Chronograf UI always preffer alert rule names.

func HTTPOut

func HTTPOut(rule chronograf.AlertRule) (string, error)

HTTPOut adds a kapacitor httpOutput to a tickscript

func HrefOutput

func HrefOutput(ID string) string

HrefOutput returns the link to a kapacitor task httpOut Node given an id

func InfluxOut

func InfluxOut(rule chronograf.AlertRule) (string, error)

InfluxOut creates a kapacitor influxDBOut node to write alert data to Database, RP, Measurement.

func MarshalTICK

func MarshalTICK(script string) ([]byte, error)

MarshalTICK converts tickscript to JSON representation

func Reverse

func Reverse(script chronograf.TICKScript) (chronograf.AlertRule, error)

Reverse converts tickscript to an AlertRule

func Trigger

func Trigger(rule chronograf.AlertRule) (string, error)

Trigger returns the trigger mechanism for a tickscript

func UnmarshalTICK

func UnmarshalTICK(octets []byte) (string, error)

UnmarshalTICK converts JSON to tickscript

func ValidateAlert

func ValidateAlert(service string) error

ValidateAlert checks if the alert is a valid kapacitor alert service.

func Vars

func Vars(rule chronograf.AlertRule) (string, error)

Vars builds the top level vars for a kapacitor alert script

Types

type Alert

type Alert struct{}

Alert defines alerting strings in template rendering

func (*Alert) Generate

func (a *Alert) Generate(rule chronograf.AlertRule) (chronograf.TICKScript, error)

Generate creates a Tickscript from the alertrule

type Client

type Client struct {
	URL                string
	Username           string
	Password           string
	InsecureSkipVerify bool
	ID                 chronograf.ID
	Ticker             chronograf.Ticker
	// contains filtered or unexported fields
}

Client communicates to kapacitor

func NewClient

func NewClient(url, username, password string, insecureSkipVerify bool) *Client

NewClient creates a client that interfaces with Kapacitor tasks

func (*Client) All

func (c *Client) All(ctx context.Context) (map[string]*Task, error)

All returns all tasks in kapacitor

func (*Client) Create

func (c *Client) Create(ctx context.Context, rule chronograf.AlertRule) (*Task, error)

Create builds and POSTs a tickscript to kapacitor

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, href string) error

Delete removes tickscript task from kapacitor

func (*Client) Disable

func (c *Client) Disable(ctx context.Context, href string) (*Task, error)

Disable changes the tickscript status to disabled for a given href.

func (*Client) Enable

func (c *Client) Enable(ctx context.Context, href string) (*Task, error)

Enable changes the tickscript status to disabled for a given href.

func (*Client) Get

func (c *Client) Get(ctx context.Context, id string) (*Task, error)

Get returns a single alert in kapacitor

func (*Client) Href

func (c *Client) Href(ID string) string

Href returns the link to a kapacitor task given an id

func (*Client) HrefOutput

func (c *Client) HrefOutput(ID string) string

HrefOutput returns the link to a kapacitor task httpOut Node given an id

func (*Client) List added in v1.9.4

func (c *Client) List(ctx context.Context, opts *client.ListTasksOptions, parseRules bool) (map[string]*Task, error)

List kapacitor tasks according to options supplied

func (*Client) Reverse

func (c *Client) Reverse(id string, script chronograf.TICKScript) chronograf.AlertRule

Reverse builds a chronograf.AlertRule and its QueryConfig from a tickscript

func (*Client) Status

func (c *Client) Status(ctx context.Context, href string) (string, error)

Status returns the status of a task in kapacitor

func (*Client) Update

func (c *Client) Update(ctx context.Context, href string, rule chronograf.AlertRule) (*Task, error)

Update changes the tickscript of a given id.

type CommonVars

type CommonVars struct {
	DB          string
	RP          string
	Measurement string
	Name        string
	Message     string
	TriggerType string
	GroupBy     []string
	Filter      WhereFilter
	Period      string
	Every       string
	Detail      string
}

CommonVars includes all the variables of a chronograf TICKScript

type CritCondition

type CritCondition struct {
	Operators []string
}

CritCondition represents the operators that determine when the alert should go critical

type DeadmanVars

type DeadmanVars struct{}

DeadmanVars represents a deadman alert

type Error

type Error string

Error are kapacitor errors due to communication or processing of TICKscript to kapacitor

func (Error) Error

func (e Error) Error() string

type FieldFunc

type FieldFunc struct {
	Field string
	Func  string
}

FieldFunc represents the field used as the alert value and its optional aggregate function

type KapaClient

type KapaClient interface {
	CreateTask(opt client.CreateTaskOptions) (client.Task, error)
	Task(link client.Link, opt *client.TaskOptions) (client.Task, error)
	ListTasks(opt *client.ListTasksOptions) ([]client.Task, error)
	UpdateTask(link client.Link, opt client.UpdateTaskOptions) (client.Task, error)
	DeleteTask(link client.Link) error
}

KapaClient represents a connection to a kapacitor instance

func NewKapaClient

func NewKapaClient(url, username, password string, insecureSkipVerify bool) (KapaClient, error)

NewKapaClient creates a Kapacitor client connection

type NotEmpty

type NotEmpty struct {
	Err error
}

NotEmpty is an error collector checking if strings are empty values

func (*NotEmpty) Valid

func (n *NotEmpty) Valid(name, s string) error

Valid checks if string s is empty and if so reports an error using name

type PaginatingKapaClient

type PaginatingKapaClient struct {
	KapaClient
	FetchRate int // specifies the number of elements to fetch from Kapacitor at a time
}

PaginatingKapaClient is a Kapacitor client that automatically navigates through Kapacitor's pagination to fetch all results

func (*PaginatingKapaClient) ListTasks

func (p *PaginatingKapaClient) ListTasks(opts *client.ListTasksOptions) ([]client.Task, error)

ListTasks lists all available tasks from Kapacitor, navigating pagination as it fetches them

type RangeVars

type RangeVars struct {
	Lower string
	Upper string
}

RangeVars represents the critical range where an alert occurs

type RelativeVars

type RelativeVars struct {
	Shift string
	Crit  string
}

RelativeVars represents the critical range and time in the past an alert occurs

type Task

type Task struct {
	ID         string                // Kapacitor ID
	Href       string                // Kapacitor relative URI
	HrefOutput string                // Kapacitor relative URI to HTTPOutNode
	Rule       chronograf.AlertRule  // Rule is the rule that represents this Task
	TICKScript chronograf.TICKScript // TICKScript is the running script
}

Task represents a running kapacitor task

func NewTask

func NewTask(task *client.Task) *Task

NewTask creates a task from a kapacitor client task

func NewTaskWithParsing added in v1.9.4

func NewTaskWithParsing(task *client.Task, parse bool) *Task

NewTask creates a task from a kapacitor client task with optional parsing of alert rule

type ThresholdVars

type ThresholdVars struct {
	Crit string
}

ThresholdVars represents the critical value where an alert occurs

type WhereFilter

type WhereFilter struct {
	TagValues map[string][]string // Tags are filtered by an array of values
	Operator  string              // Operator is == or !=
}

WhereFilter filters the stream data in a TICKScript

Jump to

Keyboard shortcuts

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