opentsdb

package module
v0.0.0-...-94d1d62 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2016 License: MIT Imports: 14 Imported by: 2

README

opentsdb

Go Report Card

Client library for golang for writing datapoint to OpenTSDB

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustReplace

func MustReplace(s, replacement string) string

MustReplace replace invalid, for OpenTSDB, characters from s and replace it with given replacement See: http://opentsdb.net/docs/build/html/user_guide/writing.html#metrics-and-tags

Types

type Client

type Client struct {
	Queue chan *DataPoint
	Clock chan *Timer

	// Errors is channel for errors from workers, client should drain it
	Errors chan error

	// Dropped is number of dropped metrics on Push
	// If this number more than zero, than you should increase bufferSize
	Dropped int64

	// Sent is number of sent metrics by all workers from beginning of time
	Sent int64
	// contains filtered or unexported fields
}

A Client is an OpenTSDB client. It should be created with NewClient.

func NewClient

func NewClient(host string, bufferSize int, timeout time.Duration) (*Client, error)

NewClient will create you a new client for OpenTSDB host could be ip address or hostname and may contain port bufferSize if size of internal Queue for workers

func (*Client) Push

func (client *Client) Push(dp *DataPoint) error

Push will add given dp to internal queue. If queue already full, then Push will return error

func (*Client) Send

func (client *Client) Send(postman *Postman, batch DataPoints) error

Send make actual http request to send datapoint to OpenTSDB, and validates, that all went ok. If something is wrong it will requeue all data back to internal queue and return error

func (*Client) StartWorkers

func (client *Client) StartWorkers(workers, batchSize int, timeout time.Duration)

StartWorkers will start given number of workers that will consume and process metrics that you Push to client

type DataPoint

type DataPoint struct {
	Metric    string      `json:"metric"`
	Timestamp int64       `json:"timestamp"`
	Value     interface{} `json:"value"`
	Tags      Tags        `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) String

func (dp DataPoint) String() string

sys.cpu.user host=webserver01,cpu=1 1356998400 0 <metric> <timestamp> <value> <tagk=tagv> [<tagkN=tagvN>]

type DataPoints

type DataPoints []*DataPoint

DataPoints holds multiple DataPoints: http://opentsdb.net/docs/build/html/api_http/put.html#example-multiple-data-point-put.

func (DataPoints) Len

func (dps DataPoints) Len() int

func (DataPoints) Less

func (dps DataPoints) Less(i, j int) bool

func (DataPoints) Swap

func (dps DataPoints) Swap(i, j int)

type Postman

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

Postman is http client for POSTing of gzip json to TSDB

func NewPostman

func NewPostman(timeout time.Duration) *Postman

NewPostman initialize http.Client and all needed buffers for new new Postman

func (*Postman) Post

func (postman *Postman) Post(batch DataPoints, url string) (err error)

Post will make POST request to OpenTSDB at given url and verify response

type Tags

type Tags map[string]string

Tags is a helper class for tags.

func (Tags) Set

func (tags Tags) Set(key, value string)

Set add new tag to Tags, and cleans it

func (Tags) String

func (tags Tags) String() string

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

type Timer

type Timer struct {
	Timestamp int64
	Start     time.Time
	Stop      time.Time
}

Timer is struct for passing information about "wallclock" duration of POSTing of batch of metrics for given timestamp

Jump to

Keyboard shortcuts

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