datasource

package
v0.0.0-...-d369a32 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: MIT Imports: 30 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckInfluxDBQuery

func CheckInfluxDBQuery(s string) (map[string]interface{}, error)

CheckInfluxDBQuery check if the query statement is valid

func HasTimeCondition

func HasTimeCondition(statement *influxql.SelectStatement) bool

HasTimeCondition check if the select statement has time condition

func MetricString

func MetricString(data map[string]string) string

MetricString 根据参数生成 metric 表达式

func Register

func Register(name string, creator EngineCreator)

Register add a new engine which will be used to init datasource

func ReleasePoints

func ReleasePoints(points ...Point)

ReleasePoints put the point into pool

Types

type Datasource

type Datasource struct {
	ID          int64            `json:"id" db:"id"`
	Name        string           `json:"name" db:"name"`
	Type        string           `json:"type" db:"type"`
	Settings    string           `json:"settings" db:"settings"`
	IsPublic    bool             `json:"is_public" db:"is_public"`
	Owners      types.StringList `json:"owners" db:"owners"`
	Description string           `json:"description" db:"description"`
	CreatedTime time.Time        `json:"created_time" db:"created_time"`
	UpdatedTime time.Time        `json:"updated_time" db:"updated_time"`

	Engine `json:"-"`
}

Datasource 代表一个数据源, 数据源是用来获取告警指标的

func InitDatasource

func InitDatasource(src Datasource) (Datasource, error)

InitDatasource set the Engine value

type Engine

type Engine interface {
	Query(time.Time, string) ([]Point, error)
	CheckQuery(time.Time, string) error
	Close() error
}

Engine represent a data source store meta data

func NewInfluxdbDataSource

func NewInfluxdbDataSource(options map[string]interface{}) (Engine, error)

NewInfluxdbDataSource create a new influxdb data source

func NewMySQLDataSource

func NewMySQLDataSource(options map[string]interface{}) (Engine, error)

NewMySQLDataSource create a new influxdb data source

func NewPrometheusDataSource

func NewPrometheusDataSource(options map[string]interface{}) (Engine, error)

NewPrometheusDataSource create a new influxdb data source

func NewURLDataSource

func NewURLDataSource(options map[string]interface{}) (Engine, error)

NewURLDataSource used to create a url datasource engine

type EngineCreator

type EngineCreator func(map[string]interface{}) (Engine, error)

EngineCreator used to create datasource engine

type Point

type Point interface {
	Data() map[string]interface{}
	Labels() map[string]string
	Values() map[string]interface{}
	NoValue() bool
}

Point 代表通用的指标返回值 Data() 返回的是用来做阈值判断和生成告警内容的数据 Labels() 返回的是数据 Label, 主要用于事件的 Metric 配对, 相同 Labels() 结果的多个 Point 被视为同一个指标

func NewPoint

func NewPoint(tags map[string]string, fields map[string]interface{}) Point

NewPoint 返回一个通用的 Point 该 Point 的 Data() 会返回 tags + fields 的数据, Labels() 只返回 tags 数据

type Prometheus

type Prometheus struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

Prometheus represent the Prometheus datasource

func (*Prometheus) CheckQuery

func (src *Prometheus) CheckQuery(now time.Time, query string) error

CheckQuery check if the query is valid

func (*Prometheus) Close

func (src *Prometheus) Close() error

Close has no op

func (*Prometheus) Query

func (src *Prometheus) Query(now time.Time, query string) ([]Point, error)

Query fetch the metrics data from prometheus database

Jump to

Keyboard shortcuts

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