expr

package
v0.0.0-...-a19e79c Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2015 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownOp = fmt.Errorf("expr: unknown op type")
View Source
var Graphite = map[string]parse.Func{
	"graphiteBand": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeScalar},
		Return: parse.TypeSeriesSet,
		Tags:   graphiteTagQuery,
		F:      GraphiteBand,
	},
	"graphite": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString},
		Return: parse.TypeSeriesSet,
		Tags:   graphiteTagQuery,
		F:      GraphiteQuery,
	},
}

Graphite defines functions for use with a Graphite backend.

View Source
var Influx = map[string]parse.Func{
	"influx": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString},
		Return: parse.TypeSeriesSet,
		Tags:   influxTag,
		F:      InfluxQuery,
	},
}

Influx is a map of functions to query InfluxDB.

View Source
var LogstashElastic = map[string]parse.Func{
	"lscount": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString},
		Return: parse.TypeSeriesSet,
		Tags:   logstashTagQuery,
		F:      LSCount,
	},
	"lsstat": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeString},
		Return: parse.TypeSeriesSet,
		Tags:   logstashTagQuery,
		F:      LSStat,
	},
}

The following are specific functions that query an elastic instance populated by logstash. They are only loaded when the elastic hosts are set in the config file

View Source
var TSDB = map[string]parse.Func{
	"band": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeScalar},
		Return: parse.TypeSeriesSet,
		Tags:   tagQuery,
		F:      Band,
	},
	"change": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString},
		Return: parse.TypeNumberSet,
		Tags:   tagQuery,
		F:      Change,
	},
	"count": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString},
		Return: parse.TypeScalar,
		F:      Count,
	},
	"q": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString},
		Return: parse.TypeSeriesSet,
		Tags:   tagQuery,
		F:      Query,
	},
	"window": {
		Args:   []parse.FuncType{parse.TypeString, parse.TypeString, parse.TypeString, parse.TypeScalar, parse.TypeString},
		Return: parse.TypeSeriesSet,
		Tags:   tagQuery,
		F:      Window,
		Check:  windowCheck,
	},
}

TSDB defines functions for use with an OpenTSDB backend.

Functions

func ProcessLSKeys

func ProcessLSKeys(keystring, filter string, filtered *elastic.FilteredQuery) ([]lsKeyMatch, error)

This creates the elastic filter porition of a query

Types

type AlertKey

type AlertKey string

func NewAlertKey

func NewAlertKey(name string, group opentsdb.TagSet) AlertKey

func ParseAlertKey

func ParseAlertKey(a string) (ak AlertKey, err error)

func (AlertKey) Group

func (a AlertKey) Group() opentsdb.TagSet

Group returns the tagset of this alert key. Will panic if a is not a valid AlertKey. OpenTSDB tag validation errors are ignored.

func (AlertKey) Name

func (a AlertKey) Name() string

type AlertKeys

type AlertKeys []AlertKey

func (AlertKeys) Len

func (a AlertKeys) Len() int

func (AlertKeys) Less

func (a AlertKeys) Less(i, j int) bool

func (AlertKeys) Swap

func (a AlertKeys) Swap(i, j int)

type AlertStatusProvider

type AlertStatusProvider interface {
	GetUnknownAndUnevaluatedAlertKeys(alertName string) (unknown, unevaluated []AlertKey)
}

Alert Status Provider is used to provide information about alert results. This facilitates alerts referencing other alerts, even when they go unknown or unevaluated.

type Computation

type Computation struct {
	Text  string
	Value interface{}
}

type Computations

type Computations []Computation

type Expr

type Expr struct {
	*parse.Tree
}

func New

func New(expr string, funcs ...map[string]parse.Func) (*Expr, error)

func (*Expr) Execute

func (e *Expr) Execute(c opentsdb.Context, g graphite.Context, l LogstashElasticHosts, influxConfig client.Config, cache *cache.Cache, T miniprofiler.Timer, now time.Time, autods int, unjoinedOk bool, search *search.Search, squelched func(tags opentsdb.TagSet) bool, history AlertStatusProvider) (r *Results, queries []opentsdb.Request, err error)

Execute applies a parse expression to the specified OpenTSDB context, and returns one result per group. T may be nil to ignore timings.

func (*Expr) ExecuteState

func (e *Expr) ExecuteState(s *State, T miniprofiler.Timer) (r *Results, queries []opentsdb.Request, err error)

func (*Expr) MarshalJSON

func (e *Expr) MarshalJSON() ([]byte, error)

type LogstashElasticHosts

type LogstashElasticHosts []string

This is an array of Logstash hosts and exists as a type for something to attach methods to. The elasticsearch library will use the listed to hosts to discover all of the hosts in the config

func (*LogstashElasticHosts) GenIndices

func (e *LogstashElasticHosts) GenIndices(r *LogstashRequest) (string, error)

GenIndicies generates the indexes to hit based on the timeframe of the query. It assumes all

func (LogstashElasticHosts) InitClient

func (e LogstashElasticHosts) InitClient() error

InitClient sets up the elastic client. If the client has already been initalized it is a noop

func (LogstashElasticHosts) Query

Query takes a Logstash request, applies it a search service, and then queries elasticsearch.

type LogstashRequest

type LogstashRequest struct {
	IndexRoot  string // The root of all index names i.e. logstash in logstash-2014-04-25
	Start      *time.Time
	End        *time.Time
	Source     *elastic.SearchSource // This the object that we build queries in
	KeyMatches []lsKeyMatch
}

LogstashRequest is a container for the information needed to query elasticsearch.

func LSBaseQuery

func LSBaseQuery(now time.Time, indexRoot string, l LogstashElasticHosts, keystring string, filter, sduration, eduration string, size int) (*LogstashRequest, error)

LSBaseQuery builds the base query that both LSCount and LSStat share

func (*LogstashRequest) CacheKey

func (r *LogstashRequest) CacheKey() string

CacheKey returns the text of the elastic query. That text is the indentifer for the query in the cache

type Number

type Number float64

func (Number) MarshalJSON

func (n Number) MarshalJSON() ([]byte, error)

func (Number) Type

func (n Number) Type() parse.FuncType

func (Number) Value

func (n Number) Value() interface{}

type Result

type Result struct {
	Computations
	Value
	Group opentsdb.TagSet
}

type ResultSlice

type ResultSlice []*Result

func (ResultSlice) DescByValue

func (r ResultSlice) DescByValue() ResultSlice

func (ResultSlice) Filter

func (r ResultSlice) Filter(filter opentsdb.TagSet) ResultSlice

Filter returns a slice with only the results that have a tagset that conforms to the given key/value pair restrictions

type ResultSliceByGroup

type ResultSliceByGroup ResultSlice

func (ResultSliceByGroup) Len

func (r ResultSliceByGroup) Len() int

func (ResultSliceByGroup) Less

func (r ResultSliceByGroup) Less(i, j int) bool

func (ResultSliceByGroup) Swap

func (r ResultSliceByGroup) Swap(i, j int)

type ResultSliceByValue

type ResultSliceByValue ResultSlice

func (ResultSliceByValue) Len

func (r ResultSliceByValue) Len() int

func (ResultSliceByValue) Less

func (r ResultSliceByValue) Less(i, j int) bool

func (ResultSliceByValue) Swap

func (r ResultSliceByValue) Swap(i, j int)

type Results

type Results struct {
	Results ResultSlice
	// If true, ungrouped joins from this set will be ignored.
	IgnoreUnjoined bool
	// If true, ungrouped joins from the other set will be ignored.
	IgnoreOtherUnjoined bool
	// If non nil, will set any NaN value to it.
	NaNValue *float64
}

func Abs

func Abs(e *State, T miniprofiler.Timer, series *Results) *Results

func Avg

func Avg(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Band

func Band(e *State, T miniprofiler.Timer, query, duration, period string, num float64) (r *Results, err error)

func CCount

func CCount(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Change

func Change(e *State, T miniprofiler.Timer, query, sduration, eduration string) (r *Results, err error)

func Count

func Count(e *State, T miniprofiler.Timer, query, sduration, eduration string) (r *Results, err error)

func Des

func Des(e *State, T miniprofiler.Timer, series *Results, alpha float64, beta float64) *Results

func Dev

func Dev(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Diff

func Diff(e *State, T miniprofiler.Timer, series *Results) (r *Results, err error)

func DropG

func DropG(e *State, T miniprofiler.Timer, series *Results, threshold *Results) (*Results, error)

func DropGe

func DropGe(e *State, T miniprofiler.Timer, series *Results, threshold *Results) (*Results, error)

func DropL

func DropL(e *State, T miniprofiler.Timer, series *Results, threshold *Results) (*Results, error)

func DropLe

func DropLe(e *State, T miniprofiler.Timer, series *Results, threshold *Results) (*Results, error)

func DropNA

func DropNA(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func DropValues

func DropValues(e *State, T miniprofiler.Timer, series *Results, threshold *Results, dropFunction func(float64, float64) bool) (*Results, error)

func Duration

func Duration(e *State, T miniprofiler.Timer, d string) (*Results, error)

func Epoch

func Epoch(e *State, T miniprofiler.Timer) (*Results, error)

func Filter

func Filter(e *State, T miniprofiler.Timer, series *Results, number *Results) (*Results, error)

func First

func First(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Forecast_lr

func Forecast_lr(e *State, T miniprofiler.Timer, series *Results, y *Results) (r *Results, err error)

func GraphiteBand

func GraphiteBand(e *State, T miniprofiler.Timer, query, duration, period, format string, num float64) (r *Results, err error)

func GraphiteQuery

func GraphiteQuery(e *State, T miniprofiler.Timer, query string, sduration, eduration, format string) (r *Results, err error)

func InfluxQuery

func InfluxQuery(e *State, T miniprofiler.Timer, db, query, startDuration, endDuration, groupByInterval string) (*Results, error)

func LSCount

func LSCount(e *State, T miniprofiler.Timer, index_root, keystring, filter, interval, sduration, eduration string) (r *Results, err error)

LScount takes 6 arguments and returns the per second for matching documents. index_root is the root name of the index to hit, the format is expected to be fmt.Sprintf("%s-%s", index_root, d.Format("2006.01.02")). keystring creates groups (like tagsets) and can also filter those groups. It is the format of "field:regex,field:regex..." The :regex can be ommited. filter is an Elastic regexp query that can be applied to any field. It is in the same format as the keystring argument. interval is in the format of an opentsdb time duration, and tells elastic what the bucket size should be. The result will be normalized to a per second rate regardless of what this is set to. sduration and end duration are the time bounds for the query and are in opentsdb's relative time format: http://opentsdb.net/docs/build/html/user_guide/query/dates.html Caveats: 1) There is currently no escaping in the keystring, so if you regex needs to have a comma or double quote you are out of luck. 2) If the type of the field value in Elastic (aka the mapping) is a number then the regexes won't act as a regex. The only thing you can do is an exact match on the number, ie "eventlogid:1234". It is recommended that anything that is a identifer should be stored as a string since they are not numbers even if they are made up entirely of numerals.

func LSDateHistogram

func LSDateHistogram(e *State, T miniprofiler.Timer, index_root, keystring, filter, interval, sduration, eduration, stat_field, rstat string, size int) (r *Results, err error)

LSDateHistorgram builds the aggregation query using subaggregations. The result is a grouped timer series that Bosun can understand

func LSStat

func LSStat(e *State, T miniprofiler.Timer, index_root, keystring, filter, field, rstat, interval, sduration, eduration string) (r *Results, err error)

LSStat returns a bucketed statistical reduction for the specified field. The arguments are the same LSCount with the addition of the following: The field is the field to generate stats for - this must be a number type in elastic. rstat is the reduction function to use per bucket and can be one of the following: avg, min, max, sum, sum_of_squares, variance, std_deviation

func Last

func Last(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Length

func Length(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Limit

func Limit(e *State, T miniprofiler.Timer, series *Results, v float64) (*Results, error)

func Max

func Max(e *State, T miniprofiler.Timer, series *Results) (r *Results, err error)

func Median

func Median(e *State, T miniprofiler.Timer, series *Results) (r *Results, err error)

func Min

func Min(e *State, T miniprofiler.Timer, series *Results) (r *Results, err error)

func NV

func NV(e *State, T miniprofiler.Timer, series *Results, v float64) (results *Results, err error)

func Percentile

func Percentile(e *State, T miniprofiler.Timer, series *Results, p *Results) (r *Results, err error)

func Query

func Query(e *State, T miniprofiler.Timer, query, sduration, eduration string) (r *Results, err error)

func Rename

func Rename(e *State, T miniprofiler.Timer, series *Results, s string) (*Results, error)

func Since

func Since(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Sort

func Sort(e *State, T miniprofiler.Timer, series *Results, order string) (*Results, error)

func Streak

func Streak(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Sum

func Sum(e *State, T miniprofiler.Timer, series *Results) (*Results, error)

func Transpose

func Transpose(e *State, T miniprofiler.Timer, d *Results, gp string) (*Results, error)

func Ungroup

func Ungroup(e *State, T miniprofiler.Timer, d *Results) (*Results, error)

func Window

func Window(e *State, T miniprofiler.Timer, query, duration, period string, num float64, rfunc string) (*Results, error)

func (*Results) NaN

func (r *Results) NaN() Number

type Scalar

type Scalar float64

func (Scalar) MarshalJSON

func (s Scalar) MarshalJSON() ([]byte, error)

func (Scalar) Type

func (s Scalar) Type() parse.FuncType

func (Scalar) Value

func (s Scalar) Value() interface{}

type Series

type Series map[time.Time]float64

Series is the standard form within bosun to represent timeseries data.

func (Series) MarshalJSON

func (s Series) MarshalJSON() ([]byte, error)

func (Series) Type

func (s Series) Type() parse.FuncType

func (Series) Value

func (s Series) Value() interface{}

type SortablePoint

type SortablePoint struct {
	T time.Time
	V float64
}

type SortableSeries

type SortableSeries []SortablePoint

SortableSeries is an alternative datastructure for timeseries data, which stores points in a time-ordered fashion instead of a map. see discussion at https://github.com/bosun-monitor/bosun/pull/699

func NewSortedSeries

func NewSortedSeries(dps Series) SortableSeries

func (SortableSeries) Len

func (s SortableSeries) Len() int

func (SortableSeries) Less

func (s SortableSeries) Less(i, j int) bool

func (SortableSeries) Swap

func (s SortableSeries) Swap(i, j int)

type State

type State struct {
	*Expr

	// OpenTSDB
	Search *search.Search

	// InfluxDB
	InfluxConfig client.Config

	History AlertStatusProvider
	// contains filtered or unexported fields
}

func (*State) AddComputation

func (e *State) AddComputation(r *Result, text string, value interface{})

type Union

type Union struct {
	Computations
	A, B  Value
	Group opentsdb.TagSet
}

func (*Union) ExtendComputations

func (u *Union) ExtendComputations(o *Result)

type Value

type Value interface {
	Type() parse.FuncType
	Value() interface{}
}

Directories

Path Synopsis
Package parse builds parse trees for expressions as defined by expr.
Package parse builds parse trees for expressions as defined by expr.

Jump to

Keyboard shortcuts

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