grafana

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(mux *http.ServeMux, prefix string, handler Handler)

Handle installs a handler implementing the simple-json-datasource API on mux.

The function adds three routes to mux, for /annotations, /query, and /search.

func HandleAnnotations

func HandleAnnotations(mux *http.ServeMux, prefix string, handler AnnotationsHandler)

HandleAnnotations installs a handler on /annotations.

func HandleQuery

func HandleQuery(mux *http.ServeMux, prefix string, handler QueryHandler)

HandleQuery installs a handler on /query.

func HandleSearch

func HandleSearch(mux *http.ServeMux, prefix string, handler SearchHandler)

HandleSearch installs a handler on /search.

func NewAnnotationsHandler

func NewAnnotationsHandler(handler AnnotationsHandler) http.Handler

NewAnnotationsHandler returns a new http.Handler which delegates /annotations API calls to the given annotations handler.

func NewHandler

func NewHandler(prefix string, handler Handler) http.Handler

NewHandler returns a new http.Handler that implements the simple-json-datasource API.

func NewQueryHandler

func NewQueryHandler(handler QueryHandler) http.Handler

NewQueryHandler returns a new http.Handler which delegates /query API calls to the given query handler.

func NewSearchHandler

func NewSearchHandler(handler SearchHandler) http.Handler

NewSearchHandler returns a new http.Handler which delegates /search API calls to the given search handler.

Types

type Annotation

type Annotation struct {
	Time     time.Time
	Title    string
	Text     string
	Enabled  bool
	ShowLine bool
	Tags     []string
}

Annotation represents a single Grafana annotation.

type AnnotationsHandler

type AnnotationsHandler interface {
	// ServeAnnotations
	ServeAnnotations(ctx context.Context, res AnnotationsResponse, req *AnnotationsRequest) error
}

AnnotationsHandler is the handler for the /annotations endpoint in the simple-json-datasource API.

type AnnotationsHandlerFunc

type AnnotationsHandlerFunc func(context.Context, AnnotationsResponse, *AnnotationsRequest) error

AnnotationsHandlerFunc makes it possible to use regular function types as annotations handlers.

func (AnnotationsHandlerFunc) ServeAnnotations

ServeAnnotations calls f, satisfies the AnnotationsHandler interface.

type AnnotationsRequest

type AnnotationsRequest struct {
	From       time.Time
	To         time.Time
	Name       string
	Datasource string
	IconColor  string
	Query      string
	Enable     bool
}

AnnotationsRequest represents a request received on the /annotations endpoint.

Note: It's not really clear if this request is intended to add a new annotation into the data source, neither how the name and datasource fields are supposed to be used. It seems to work to treat it as a read-only request for annotations on the given time range and query.

type AnnotationsResponse

type AnnotationsResponse interface {
	// WriteAnnotation writes an annotation to the response. The method may be
	// called multiple times.
	WriteAnnotation(Annotation)
}

AnnotationsResponse is an interface used to an annotations request.

type Column

type Column struct {
	Text string     `json:"text"`
	Type ColumnType `json:"type,omitempty"`
	Sort bool       `json:"sort,omitempty"`
	Desc bool       `json:"desc,omitempty"`
}

Column is a data structure representing a table column.

func AscCol

func AscCol(text string, colType ColumnType) Column

AscCol constructs a ne Column value from a text a column type, which is configured as a sorted column in ascending order.

func Col

func Col(text string, colType ColumnType) Column

Col constructs a new Column value from a text and column type.

func DescCol

func DescCol(text string, colType ColumnType) Column

DescCol constructs a ne Column value from a text a column type, which is configured as a sorted column in descending order.

type ColumnType

type ColumnType string

ColumnType is an enumeration of the various column types supported by Grafana.

const (
	Untyped ColumnType = ""
	String  ColumnType = "string"
	Time    ColumnType = "time"
	Number  ColumnType = "number"
)

type Handler

type Handler interface {
	AnnotationsHandler
	QueryHandler
	SearchHandler
}

Handler is an interface that must be implemented by types that intend to act as a grafana data source using the simple-json-datasource plugin.

See https://github.com/grafana/simple-json-datasource for more details about the implementation.

type QueryHandler

type QueryHandler interface {
	// ServeQuery is expected to reply with a list of data points for the given
	// "target" and time range (or a set of rows for table requests).
	//
	// Note: my understanding is that "target" is some kind of identifier that
	// describes some data set in the source (like a SQL query for example), but
	// it's treated as an opaque blob of data by Grafana itself.
	ServeQuery(ctx context.Context, res QueryResponse, req *QueryRequest) error
}

QueryHandler is the handler for the /query endpoint in the simple-json-datasource API.

type QueryHandlerFunc

type QueryHandlerFunc func(context.Context, QueryResponse, *QueryRequest) error

QueryHandlerFunc makes it possible to use regular function types as query handlers.

func (QueryHandlerFunc) ServeQuery

func (f QueryHandlerFunc) ServeQuery(ctx context.Context, res QueryResponse, req *QueryRequest) error

ServeQuery calls f, satisfies the QueryHandler interface.

type QueryRequest

type QueryRequest struct {
	From          time.Time
	To            time.Time
	Interval      time.Duration
	Targets       []Target
	MaxDataPoints int
}

QueryRequest represents a request received on the /query endpoint.

type QueryResponse

type QueryResponse interface {
	// Timeserie returns a TimeserieWriter which can be used to output the
	// datapoint in response to a timeserie request.
	Timeserie(target string) TimeserieWriter

	// Table returns a TableWriter which can be used to output the rows in
	// response to a table request.
	Table(columns ...Column) TableWriter
}

QueryResponse is an interface used to respond to a search request.

type SearchHandler

type SearchHandler interface {
	// ServeSearch is expected to implement the search functionality of a
	// Grafana data source.
	//
	// Note: It's not really clear how search is implemented, I think the
	// "target" field in the request is some kind of prefix or keyword to
	// use to return a list of potential matches that can be used in a /query
	// request.
	ServeSearch(ctx context.Context, res SearchResponse, req *SearchRequest) error
}

SearchHandler is the handler for the /search endpoint in the simple-json-datasource API.

type SearchHandlerFunc

type SearchHandlerFunc func(context.Context, SearchResponse, *SearchRequest) error

SearchHandlerFunc makes it possible to use regular function types as search handlers.

func (SearchHandlerFunc) ServeSearch

func (f SearchHandlerFunc) ServeSearch(ctx context.Context, res SearchResponse, req *SearchRequest) error

ServeSearch calls f, satisfies the SearchHandler interface.

type SearchRequest

type SearchRequest struct {
	Target string
}

SearhRequest represents a request received on the /search endpoint.

type SearchResponse

type SearchResponse interface {
	// WriteTarget writes target in the response, the method may be called
	// multiple times.
	WriteTarget(target string)

	// WriteTargetValue writes the pair of target and value in the response,
	// the method may be called multiple times.
	WriteTargetValue(target string, value interface{})
}

SearchResponse is an interface used to respond to a search request.

type TableWriter

type TableWriter interface {
	WriteRow(values ...interface{})
}

TableWriter is an interface used to write timeserie data in response to a query.

type Target

type Target struct {
	Query string     `json:"target"`
	RefID string     `json:"refId"`
	Type  TargetType `json:"type"`
}

Target is a data structure representing the target of a query.

type TargetType

type TargetType string

TargetType is an enumeration of the various target types supported by Grafana.

const (
	Timeserie TargetType = "timeserie"
	Table     TargetType = "table"
)

type TimeserieWriter

type TimeserieWriter interface {
	WriteDatapoint(value float64, time time.Time)
}

TimeserieWriter is an interface used to write timeserie data in response to a query.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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