opentsdb

package
v0.0.0-...-7afe134 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2014 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TSDBTimeFormat = "2006/01/02-15:04:05"

Variables

View Source
var DefaultClient = &http.Client{
	Timeout: time.Minute,
}

DefaultClient is the default http client for requests.

Functions

func CanonicalTime

func CanonicalTime(v interface{}) (string, error)

CanonicalTime converts v to a string for use with OpenTSDB's `/` route.

func Clean

func Clean(s string) (string, error)

Clean is Replace with an empty replacement string.

func FilterTags

func FilterTags(r *Request, tr ResponseSet)

FilterTags removes tagks in tr not present in r. Does nothing in the event of multiple queries in the request.

func MustReplace

func MustReplace(s, replacement string) string

MustReplace is like Replace, but returns an empty string on error.

func ParseAbsTime

func ParseAbsTime(s string) (time.Time, error)

ParseAbsTime returns the time of s, which must be of any non-relative (not "X-ago") format supported by OpenTSDB.

func ParseTime

func ParseTime(v interface{}) (time.Time, error)

ParseTime returns the time of v, which can be of any format supported by OpenTSDB.

func Replace

func Replace(s, replacement string) (string, error)

Replace removes characters from s that are invalid for OpenTSDB metric and tag values and replaces them. See: http://opentsdb.net/docs/build/html/user_guide/writing.html#metrics-and-tags

func ReplaceTags

func ReplaceTags(text string, group TagSet) string

ReplaceTags replaces all tag-like strings with tags from the given group. For example, given the string "test.metric{host=*}" and a TagSet with host=test.com, this returns "test.metric{host=test.com}".

func TryParseAbsTime

func TryParseAbsTime(v interface{}) interface{}

func ValidTag

func ValidTag(s string) bool

ValidTag returns true if s is a valid metric or tag.

Types

type Cache

type Cache struct {
	Host string
	// Limit limits response size in bytes
	Limit int64
	// FilterTags removes tagks from results if that tagk was not in the request
	FilterTags bool
	// contains filtered or unexported fields
}

func NewCache

func NewCache(host string, limit int64) *Cache

func (*Cache) Query

func (c *Cache) Query(r *Request) (tr ResponseSet, err error)

type Context

type Context interface {
	Query(*Request) (ResponseSet, error)
}

type DataPoint

type DataPoint struct {
	Metric    string      `json:"metric"`
	Timestamp int64       `json:"timestamp"`
	Value     interface{} `json:"value"`
	Tags      TagSet      `json:"tags"`
}

func (*DataPoint) MarshalJSON

func (d *DataPoint) MarshalJSON() ([]byte, error)

type Duration

type Duration time.Duration

func GetDuration

func GetDuration(r *Request) (Duration, error)

GetDuration returns the duration from the request's start to end.

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration is equivalent to time.ParseDuration, but supports time units specified at http://opentsdb.net/docs/build/html/user_guide/query/dates.html.

func (Duration) Seconds

func (d Duration) Seconds() float64

func (Duration) String

func (d Duration) String() string

type Host

type Host string

func (Host) Query

func (h Host) Query(r *Request) (ResponseSet, error)

type MultiDataPoint

type MultiDataPoint []*DataPoint

type Point

type Point float64

type Query

type Query struct {
	Aggregator  string      `json:"aggregator"`
	Metric      string      `json:"metric"`
	Rate        bool        `json:"rate,omitempty"`
	RateOptions RateOptions `json:"rateOptions,omitempty"`
	Downsample  string      `json:"downsample,omitempty"`
	Tags        TagSet      `json:"tags,omitempty"`
}

func ParseQuery

func ParseQuery(query string) (q *Query, err error)

ParseQuery parses OpenTSDB queries of the form: avg:rate:cpu{k=v}. Validation errors will be returned along with a valid Query.

func (Query) String

func (q Query) String() string

type RateOptions

type RateOptions struct {
	Counter    bool  `json:"counter,omitempty"`
	CounterMax int64 `json:"counterMax,omitempty"`
	ResetValue int64 `json:"resetValue,omitempty"`
}

type Request

type Request struct {
	Start             interface{} `json:"start"`
	End               interface{} `json:"end,omitempty"`
	Queries           []*Query    `json:"queries"`
	NoAnnotations     bool        `json:"noAnnotations,omitempty"`
	GlobalAnnotations bool        `json:"globalAnnotations,omitempty"`
	MsResolution      bool        `json:"msResolution,omitempty"`
	ShowTSUIDs        bool        `json:"showTSUIDs,omitempty"`
}

func ParseRequest

func ParseRequest(req string) (*Request, error)

ParsesRequest parses OpenTSDB requests of the form: start=1h-ago&m=avg:cpu.

func RequestFromJSON

func RequestFromJSON(b []byte) (*Request, error)

func (*Request) AutoDownsample

func (r *Request) AutoDownsample(l int) error

AutoDownsample sets the avg downsample aggregator to produce l points.

func (*Request) Query

func (r *Request) Query(host string) (ResponseSet, error)

Query performs a v2 OpenTSDB request to the given host. host should be of the form hostname:port. Uses DefaultClient. Can return a RequestError.

func (*Request) QueryResponse

func (r *Request) QueryResponse(host string, client *http.Client) (*http.Response, error)

Query performs a v2 OpenTSDB request to the given host. host should be of the form hostname:port. A nil client uses DefaultClient.

func (*Request) Search

func (r *Request) Search() string

Search returns a string suitable for OpenTSDB's `/` route.

func (*Request) SetTime

func (r *Request) SetTime(t time.Time) error

SetTime adjusts the start and end time of the request to assume t is now. Relative times ("1m-ago") are changed to absolute times. Existing absolute times are adjusted by the difference between time.Now() and t.

func (*Request) String

func (r *Request) String() string

type RequestError

type RequestError struct {
	Request string
	Err     struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Details string `json:"details"`
	} `json:"error"`
}

func (*RequestError) Error

func (r *RequestError) Error() string

type Response

type Response struct {
	Metric        string           `json:"metric"`
	Tags          TagSet           `json:"tags"`
	AggregateTags []string         `json:"aggregateTags"`
	DPS           map[string]Point `json:"dps"`
}

type ResponseSet

type ResponseSet []*Response

type TagSet

type TagSet map[string]string

func ParseTags

func ParseTags(t string) (TagSet, error)

ParseTags parses OpenTSDB tagk=tagv pairs of the form: k=v,m=o. Validation errors do not stop processing, and will return a non-nil TagSet.

func (TagSet) Clean

func (t TagSet) Clean() error

Clean removes characters from t that are invalid for OpenTSDB metric and tag values. An error is returned if a resulting tag is empty.

func (TagSet) Copy

func (t TagSet) Copy() TagSet

func (TagSet) Equal

func (t TagSet) Equal(o TagSet) bool

func (TagSet) Intersection

func (t TagSet) Intersection(o TagSet) TagSet

Intersection returns the intersection of t and o.

func (TagSet) Merge

func (t TagSet) Merge(o TagSet) TagSet

Merge adds or overwrites everything from o into t and returns t.

func (TagSet) String

func (t TagSet) String() string

String converts t to an OpenTSDB-style {a=b,c=b} string, alphabetized by key.

func (TagSet) Subset

func (t TagSet) Subset(o TagSet) bool

Subset returns true if all k=v pairs in o are in t.

func (TagSet) Tags

func (t TagSet) Tags() string

Tags is identical to String() but without { and }.

Jump to

Keyboard shortcuts

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