statsd

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2016 License: BSD-2-Clause Imports: 8 Imported by: 0

README

Overview

Package statsd provides a Go dogstatsd client. Dogstatsd extends Statsd, adding tags and histograms.

Get the code

$ go get github.com/DataDog/datadog-go/statsd

Usage

// Create the client
c, err := statsd.New("127.0.0.1:8125")
if err != nil {
    log.Fatal(err)
}
// Prefix every metric with the app name
c.Namespace = "flubber."
// Send the EC2 availability zone as a tag with every metric
c.Tags = append(c.Tags, "us-east-1a")
err = c.Gauge("request.duration", 1.2, nil, 1)

Buffering Client

Dogstatsd accepts packets with multiple statsd payloads in them. Using the BufferingClient via NewBufferingClient will buffer up commands and send them when the buffer is reached or after 100msec.

Development

Run the tests with:

$ go test

Documentation

Please see: http://godoc.org/github.com/DataDog/datadog-go/statsd

License

go-dogstatsd is released under the MIT license.

Credits

Original code by ooyala.

Documentation

Overview

Package statsd provides a Go dogstatsd client. Dogstatsd extends the popular statsd, adding tags and histograms and pushing upstream to Datadog.

Refer to http://docs.datadoghq.com/guides/dogstatsd/ for information about DogStatsD.

Example Usage:

// Create the client
c, err := statsd.New("127.0.0.1:8125")
if err != nil {
    log.Fatal(err)
}
// Prefix every metric with the app name
c.Namespace = "flubber."
// Send the EC2 availability zone as a tag with every metric
c.Tags = append(c.Tags, "us-east-1a")
err = c.Gauge("request.duration", 1.2, nil, 1)

statsd is based on go-statsd-client.

Index

Constants

View Source
const (
	// Info is the "info" AlertType for events
	Info eventAlertType = "info"
	// Error is the "error" AlertType for events
	Error eventAlertType = "error"
	// Warning is the "warning" AlertType for events
	Warning eventAlertType = "warning"
	// Success is the "success" AlertType for events
	Success eventAlertType = "success"
)
View Source
const (
	// Normal is the "normal" Priority for events
	Normal eventPriority = "normal"
	// Low is the "low" Priority for events
	Low eventPriority = "low"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// Namespace to prepend to all statsd calls
	Namespace string
	// Tags are global tags to be added to every statsd call
	Tags []string

	sync.Mutex
	// contains filtered or unexported fields
}

A Client is a handle for sending udp messages to dogstatsd. It is safe to use one Client from multiple goroutines simultaneously.

func New

func New(addr string) (*Client, error)

New returns a pointer to a new Client given an addr in the format "hostname:port".

func NewBuffered

func NewBuffered(addr string, buflen int) (*Client, error)

NewBuffered returns a Client that buffers its output and sends it in chunks. Buflen is the length of the buffer in number of commands.

func (*Client) Close

func (c *Client) Close() error

Close the client connection.

func (*Client) Count

func (c *Client) Count(name string, value int64, tags []string, rate float64) error

Count tracks how many times something happened per second.

func (*Client) Event

func (c *Client) Event(e *Event) error

Event sends the provided Event.

func (*Client) Gauge

func (c *Client) Gauge(name string, value float64, tags []string, rate float64) error

Gauge measures the value of a metric at a particular time.

func (*Client) Histogram

func (c *Client) Histogram(name string, value float64, tags []string, rate float64) error

Histogram tracks the statistical distribution of a set of values.

func (*Client) Set

func (c *Client) Set(name string, value string, tags []string, rate float64) error

Set counts the number of unique elements in a group.

func (*Client) SimpleEvent

func (c *Client) SimpleEvent(title, text string) error

SimpleEvent sends an event with the provided title and text.

func (*Client) TimeInMilliseconds

func (c *Client) TimeInMilliseconds(name string, value float64, tags []string, rate float64) error

TimeInMilliseconds sends timing information in milliseconds. It is flushed by statsd with percentiles, mean and other info (https://github.com/etsy/statsd/blob/master/docs/metric_types.md#timing)

type Event

type Event struct {
	// Title of the event.  Required.
	Title string
	// Text is the description of the event.  Required.
	Text string
	// Timestamp is a timestamp for the event.  If not provided, the dogstatsd
	// server will set this to the current time.
	Timestamp time.Time
	// Hostname for the event.
	Hostname string
	// AggregationKey groups this event with others of the same key.
	AggregationKey string
	// Priority of the event.  Can be statsd.Low or statsd.Normal.
	Priority eventPriority
	// SourceTypeName is a source type for the event.
	SourceTypeName string
	// AlertType can be statsd.Info, statsd.Error, statsd.Warning, or statsd.Success.
	// If absent, the default value applied by the dogstatsd server is Info.
	AlertType eventAlertType
	// Tags for the event.
	Tags []string
}

An Event is an object that can be posted to your DataDog event stream.

func NewEvent

func NewEvent(title, text string) *Event

NewEvent creates a new event with the given title and text. Error checking against these values is done at send-time, or upon running e.Check.

func (Event) Check

func (e Event) Check() error

Check verifies that an event is valid.

func (Event) Encode

func (e Event) Encode(tags ...string) (string, error)

Encode returns the dogstatsd wire protocol representation for an event. Tags may be passed which will be added to the encoded output but not to the Event's list of tags, eg. for default tags.

Jump to

Keyboard shortcuts

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