tsdb

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Overview

Package tsdb manages everything related to the time-series database. This database will be used to store and retrieve monitoring metrics.

Index

Constants

View Source
const (
	// EventValueNotified encodes a "notified" event
	EventValueNotified = EventValue(api.Event_NOTIFIED)
	// EventValueAcknowledged encodes an "acknowledged" event
	EventValueAcknowledged = EventValue(api.Event_ACKNOWLEDGED)
	// EventValueSnoozed encodes a "snoozed" event
	EventValueSnoozed = EventValue(api.Event_SNOOZED)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity struct {
	Timestamp    time.Time
	Organization uuid.UUID
	Agent        uuid.UUID
	Version      string
	Type         string
}

Activity contains the data from an agent activity

func (*Activity) FromRow

func (a *Activity) FromRow(row []interface{}, columns []string) (err error)

FromRow populates an `Activity` using a row from a TSDB query.

type AlertEvent

type AlertEvent struct {
	Entry
	Event       EventValue
	StateReason string    // State.Reason from the TSDB
	Alert       uuid.UUID // Corresponding Alert from the DBConf
	AlertReason string    // Message sent to the user explaining why the Alert is sent
}

AlertEvent contains the data from an alert event in the TSDB.

type Entry

type Entry struct {
	Timestamp          time.Time
	Organization       uuid.UUID
	ProbeConfiguration uuid.UUID
	Probe              uuid.UUID
	Agent              uuid.UUID
	Check              uuid.UUID
	Target             uuid.UUID
}

Entry is a generic structure containing data common to all TSDB entries (probe results, states, alert events). It is meant to be embedded in each specific structure and serve as a kind of "abstract base class".

type EventValue

type EventValue int

EventValue encodes a value evaluated for an event

func EventValueFromString

func EventValueFromString(s string) (ev EventValue, err error)

EventValueFromString convert a string in EventValue

func (EventValue) String

func (ev EventValue) String() string

type InfluxTSDB

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

InfluxTSDB is a concrete implementation of `tsdb.TSDB` that uses InfluxDB as a time-series database.

func NewInfluxTSDB

func NewInfluxTSDB(address, database string) (*InfluxTSDB, error)

NewInfluxTSDB creates a new connection to an InfluxDB TSDB. The `database` argument is the name of the database to `USE` inside InfluxDB.

func (*InfluxTSDB) AddActivity

func (tsdb *InfluxTSDB) AddActivity(activity Activity) error

AddActivity adds an activity into the TSDB

func (*InfluxTSDB) AddAlertEvent

func (tsdb *InfluxTSDB) AddAlertEvent(alert AlertEvent) error

AddAlertEvent adds a new alert event to the TSDB.

func (*InfluxTSDB) AddResults

func (tsdb *InfluxTSDB) AddResults(results []Result) error

AddResults adds a batch of results from a check to the TSDB.

func (*InfluxTSDB) AddState

func (tsdb *InfluxTSDB) AddState(state State) error

AddState adds a state computed from a probe result into the TSDB

func (*InfluxTSDB) Close added in v0.8.0

func (i *InfluxTSDB) Close() error

Close closes any open connection to InfluxDB. The instance should not be used after calling Close.

func (*InfluxTSDB) GetActivity

func (tsdb *InfluxTSDB) GetActivity(organization uuid.UUID, agent uuid.UUID, opts ...QueryOption) ([]Activity, error)

GetActivity retrieves the activity for an agent from the TSDB.

func (*InfluxTSDB) GetAlertEvents

func (tsdb *InfluxTSDB) GetAlertEvents(probeConfigurations []uuid.UUID, opts ...QueryOption) ([]AlertEvent, error)

GetAlertEvents retrieves the alert events for a probeConfiguration from the TSDB.

func (*InfluxTSDB) GetResults

func (tsdb *InfluxTSDB) GetResults(check uuid.UUID, fields QueryFields, tags QueryTags, opts ...QueryOption) ([]Result, error)

GetResults retrieves results from the TSDB following the given filters

func (*InfluxTSDB) GetStates

func (tsdb *InfluxTSDB) GetStates(checks []uuid.UUID, opts ...QueryOption) ([]State, error)

GetStates retrieves the states for a check from the TSDB.

type Order

type Order bool

Order of query results: by ascending or descending timestamps

const (
	// OrderAscending returns results by ascending timestamp
	OrderAscending Order = true
	// OrderDescending returns results by descending timestamp
	OrderDescending Order = false
)

func (Order) String

func (o Order) String() string

type QueryField added in v0.8.0

type QueryField struct {
	Field    string
	Function QueryFunc
}

QueryField is used to configure queries on the TSDB

type QueryFields added in v0.8.0

type QueryFields []QueryField

QueryFields is a collection of QueryField

type QueryFunc added in v0.8.0

type QueryFunc string

QueryFunc represents a function applied on a field

const (
	None       QueryFunc = "None"
	Derivative QueryFunc = "Derivative"
)

Supported Influx functions:

type QueryOption

type QueryOption func(*queryOptions)

QueryOption is used to configure queries on the TSDB

func Count

func Count(c int) QueryOption

Count returns a QueryOption that defines a maximum number of results from the TSDB query.

func Field

func Field(k, v string) QueryOption

Field returns a QueryOption that specifies a column-value pair that the results from the TSDB must match.

func From

func From(t time.Time) QueryOption

From returns a QueryOption that defines a lower time bound to the results of the TSDB query. The query will return results starting after and including the given time.

func GroupBy

func GroupBy(g string) QueryOption

GroupBy returns a QueryOption that defines the grouping of the results from the TSDB query.

func Offset

func Offset(o int) QueryOption

Offset returns a QueryOption that offsets the result set from the TSDB query. Used for pagination.

func OrderBy

func OrderBy(o Order) QueryOption

OrderBy returns a QueryOption that defines the ordering according to time of the results from the TSDB query.

func Tag

func Tag(k string, v ...string) QueryOption

Tag returns a QueryOption that specifies a column-value pair that the results from the TSDB must match.

func To

func To(t time.Time) QueryOption

To returns a QueryOption that defines an upper time bound to the results of the TSDB query. The query will return results before and not including the given time.

type QueryTag added in v0.8.0

type QueryTag string

QueryTag is used to configure queries on the TSDB

type QueryTags added in v0.8.0

type QueryTags []QueryTag

QueryTags is a collection of QueryTag

type Result

type Result struct {
	Entry

	Tags         map[string]string
	Fields       map[string]interface{}
	Error        bool
	ErrorMessage string
	// contains filtered or unexported fields
}

Result contains all the data for the server to enter a result from a probe into the time-series database.

type State

type State struct {
	Entry
	State  int
	Reason string
}

State contains the data from a state evaluation after receiving a result in the TSDB

type TSDB

type TSDB interface {
	AddResults(results []Result) error
	GetResults(check uuid.UUID, fields QueryFields, tags QueryTags, opts ...QueryOption) ([]Result, error)

	AddState(state State) error
	GetStates(checks []uuid.UUID, opts ...QueryOption) ([]State, error)

	AddAlertEvent(alert AlertEvent) error
	GetAlertEvents(probeConfigurations []uuid.UUID, opts ...QueryOption) ([]AlertEvent, error)

	AddActivity(activity Activity) error
	GetActivity(organization uuid.UUID, agent uuid.UUID, opts ...QueryOption) ([]Activity, error)
}

TSDB represents an abstract time-series database.

Jump to

Keyboard shortcuts

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