tsdb

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: Apache-2.0 Imports: 10 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
	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
}

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

func (*AlertEvent) FromRow

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

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

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".

func (*Entry) FromRow

func (e *Entry) FromRow(row []interface{}, columns []string, tags map[string]string) (err error)

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

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) 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, 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 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 Result

type Result struct {
	Entry

	Tags   map[string]string
	Fields map[string]interface{}
}

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

func (*Result) FromRow

func (r *Result) FromRow(row []interface{}, columns []string, tags map[string]string, sch *schema) (err error)

FromRow populates a `Result` using a row from a TSDB query. Optionally takes a schema to infer types

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

func (*State) FromRow

func (s *State) FromRow(row []interface{}, columns []string, tags map[string]string) (err error)

FromRow populates a `State` using a row from a TSDB query.

type TSDB

type TSDB interface {
	AddResults(results []Result) error
	GetResults(check uuid.UUID, 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