Documentation ¶
Overview ¶
Package opentsdb defines structures for interacting with an OpenTSDB server.
Index ¶
- Constants
- Variables
- func CanonicalTime(v interface{}) (string, error)
- func Clean(s string) (string, error)
- func FilterTags(r *Request, tr ResponseSet)
- func MustReplace(s, replacement string) string
- func NewOpenTsdbNameProcessor(invalidRuneReplacement string) (name.RuneLevelProcessor, error)
- func ParseAbsTime(s string) (time.Time, error)
- func ParseTime(v interface{}) (time.Time, error)
- func Replace(s, replacement string) (string, error)
- func ReplaceTags(text string, group TagSet) string
- func TryParseAbsTime(v interface{}) interface{}
- func ValidTSDBString(s string) bool
- type Context
- type DataPoint
- type Duration
- type Filter
- type Filters
- type Host
- type LimitContext
- type MultiDataPoint
- type Point
- type Query
- type RateOptions
- type Request
- func (r *Request) AutoDownsample(l int) error
- func (r *Request) Query(host string) (ResponseSet, error)
- func (r *Request) QueryResponse(host string, client *http.Client) (*http.Response, error)
- func (r *Request) Search() string
- func (r *Request) SetTime(t time.Time) error
- func (r *Request) String() string
- type RequestError
- type Response
- type ResponseSet
- type TagSet
- func (t TagSet) AllSubsets() []string
- func (t TagSet) Clean() error
- func (t TagSet) Compatible(o TagSet) bool
- func (t TagSet) Copy() TagSet
- func (t TagSet) Equal(o TagSet) bool
- func (t TagSet) Intersection(o TagSet) TagSet
- func (t TagSet) Merge(o TagSet) TagSet
- func (a TagSet) Overlaps(b TagSet) bool
- func (t TagSet) String() string
- func (t TagSet) Subset(o TagSet) bool
- func (t TagSet) Tags() string
- func (t TagSet) Valid() bool
- type Version
Constants ¶
const ( Millisecond Duration = Duration(time.Millisecond) Second = 1000 * Millisecond Minute = 60 * Second Hour = 60 * Minute Day = Hour * 24 Week = Day * 7 Month = Day * 30 Year = Day * 365 )
const TSDBTimeFormat = "2006/01/02-15:04:05"
TSDBTimeFormat is the OpenTSDB-required time format for the time package.
Variables ¶
var DefaultClient = &http.Client{ Timeout: time.Minute, }
DefaultClient is the default http client for requests.
var Version2_1 = Version{2, 1}
OpenTSDB 2.1 version struct
var Version2_2 = Version{2, 2}
OpenTSDB 2.2 version struct
Functions ¶
func CanonicalTime ¶
CanonicalTime converts v to a string for use with OpenTSDB's `/` route.
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 ¶
MustReplace is like Replace, but returns an empty string on error.
func NewOpenTsdbNameProcessor ¶
func NewOpenTsdbNameProcessor(invalidRuneReplacement string) (name.RuneLevelProcessor, error)
NewOpenTsdbNameProcessor constructs a new name.RuneLevelProcessor which can work with the OpenTSDB name format
func ParseAbsTime ¶
ParseAbsTime returns the time of s, which must be of any non-relative (not "X-ago") format supported by OpenTSDB.
func Replace ¶
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 ¶
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{}
TryParseAbsTime attempts to parse v as an absolute time. It may be a string in the format of TSDBTimeFormat or a float64 of seconds since epoch. If so, the epoch as an int64 is returned. Otherwise, v is returned.
func ValidTSDBString ¶
ValidTSDBString returns true if s is a valid metric or tag.
Types ¶
type Context ¶
type Context interface { Query(*Request) (ResponseSet, error) Version() Version }
Context is the interface for querying an OpenTSDB server.
type DataPoint ¶
type DataPoint struct { Metric string `json:"metric"` Timestamp int64 `json:"timestamp"` Value interface{} `json:"value"` Tags TagSet `json:"tags"` }
DataPoint is a data point for the /api/put route: http://opentsdb.net/docs/build/html/api_http/put.html#example-single-data-point-put.
func (*DataPoint) MarshalJSON ¶
MarshalJSON verifies d is valid and converts it to JSON.
type Duration ¶
Duration extends time.Duration to support OpenTSDB time-format specifiers: http://opentsdb.net/docs/build/html/user_guide/query/dates.html#relative.
func GetDuration ¶
GetDuration returns the duration from the request's start to end.
func ParseDuration ¶
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) HumanString ¶
func (*Duration) UnmarshalText ¶
type Filter ¶
type Filter struct { Type string `json:"type"` TagK string `json:"tagk"` Filter string `json:"filter"` GroupBy bool `json:"groupBy"` }
func ParseFilters ¶
ParseFilters parses filters in the form of `tagk=filterFunc(...),...` It also mimics OpenTSDB's promotion of queries with a * or no function to iwildcard and literal_or respectively
type LimitContext ¶
type LimitContext 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 // Use the version to see if groupby and filters are supported TSDBVersion Version }
LimitContext is a context that enables limiting response size and filtering tags
func NewLimitContext ¶
func NewLimitContext(host string, limit int64, version Version) *LimitContext
NewLimitContext returns a new context for the given host with response sizes limited to limit bytes.
func (*LimitContext) Query ¶
func (c *LimitContext) Query(r *Request) (tr ResponseSet, err error)
Query returns the result of the request. r may be cached. The request is byte-limited and filtered by c's properties.
func (*LimitContext) Version ¶
func (c *LimitContext) Version() Version
type MultiDataPoint ¶
type MultiDataPoint []*DataPoint
MultiDataPoint holds multiple DataPoints: http://opentsdb.net/docs/build/html/api_http/put.html#example-multiple-data-point-put.
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"` Filters Filters `json:"filters,omitempty"` GroupByTags TagSet `json:"-"` }
Query is a query for a request: http://opentsdb.net/docs/build/html/api_http/query/index.html#sub-queries.
func ParseQuery ¶
ParseQuery parses OpenTSDB queries of the form: avg:rate:cpu{k=v}. Validation errors will be returned along with a valid Query.
type RateOptions ¶
type RateOptions struct { Counter bool `json:"counter,omitempty"` CounterMax int64 `json:"counterMax,omitempty"` ResetValue int64 `json:"resetValue,omitempty"` DropResets bool `json:"dropResets,omitempty"` }
RateOptions are rate options for a query.
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"` Delete bool `json:"delete,omitempty"` }
Request holds query objects: http://opentsdb.net/docs/build/html/api_http/query/index.html#requests.
func ParseRequest ¶
ParseRequest parses OpenTSDB requests of the form: start=1h-ago&m=avg:cpu.
func RequestFromJSON ¶
RequestFromJSON creates a new request from JSON.
func (*Request) AutoDownsample ¶
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 ¶
QueryResponse performs a v2 OpenTSDB request to the given host. host should be of the form hostname:port. A nil client uses DefaultClient.
type RequestError ¶
type RequestError struct { Request string Err struct { Code int `json:"code"` Message string `json:"message"` Details string `json:"details"` } `json:"error"` }
RequestError is the error structure for request errors.
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"` // fields added by translating proxy SQL string `json:"sql,omitempty"` }
Response is a query response: http://opentsdb.net/docs/build/html/api_http/query/index.html#response.
type ResponseSet ¶
type ResponseSet []*Response
ResponseSet is a Multi-Set Response: http://opentsdb.net/docs/build/html/api_http/query/index.html#example-multi-set-response.
func (ResponseSet) Copy ¶
func (r ResponseSet) Copy() ResponseSet
type TagSet ¶
TagSet is a helper class for tags.
func ParseTags ¶
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) AllSubsets ¶
func (TagSet) Clean ¶
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) Compatible ¶
Compatible returns true if all keys that are in both o and t, have the same value.
func (TagSet) Intersection ¶
Intersection returns the intersection of t and o.
func (TagSet) Overlaps ¶
Returns true if the two tagsets "overlap". Two tagsets overlap if they: 1. Have at least one key/value pair that matches 2. Have no keys in common where the values do not match
func (TagSet) String ¶
String converts t to an OpenTSDB-style {a=b,c=b} string, alphabetized by key.