dogstatsd

package module
v0.0.0-...-1d05659 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2018 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

github.com/vcabbage/dogstatsd

Go Report Card Coverage Status Build Status Build status GoDoc MIT licensed

Fork Info

This code was forked from datadog-go with the purpose of improving performance and adjusting the API.

Overview

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

Get the code

$ go get -u github.com/vcabbage/dogstatsd

Usage

// Create the client
c, err := dogstatsd.New()
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")

// Send some metrics
err = c.Gauge("request.queue_depth", 12, 1)
err = c.Timing("request.duration", duration, 1)
err = c.TimeInMilliseconds("request", 12, 1)
err = c.Incr("request.count_total", 1)
err = c.Decr("request.count_total", 1)
err = c.Count("request.count_total", 2, 1)

Buffering Client

DogStatsD accepts packets with multiple statsd payloads in them. Using the ConnBuffer option will buffer up commands and send them when the buffer is reached or after 100msec.

Unix Domain Sockets Client

DogStatsD version 6 accepts packets through a Unix Socket datagram connection. You can use this protocol by giving a unix:///path/to/dsd.socket argument to the ConnAddr option.

With this protocol, writes can become blocking if the server's receiving buffer is full. Our default behaviour is to timeout and drop the packet after 1 ms. You can set a custom timeout duration via the SetWriteTimeout method.

The default mode is to pass write errors from the socket to the caller. This includes write errors the library will automatically recover from (DogStatsD server not ready yet or is restarting). You can drop these errors and emulate the UDP behavior by setting the SkipErrors property to true. Please note that packets will be dropped in both modes.

Development

Run the tests with:

$ go test

Documentation

Please see: http://godoc.org/github.com/vcabbage/dogstatsd

License

go-dogstatsd is released under the MIT license.

Credits

Original code by ooyala.

Documentation

Overview

Package dogstatsd provides a 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.

Index

Constants

View Source
const (
	// DefaultAddr is used if no writer or address is provided.
	DefaultAddr = "127.0.0.1:8125"

	// DefaultFlushTimeout is default duration between flushing the buffer to
	// the server when buffering is enabled.
	DefaultFlushTimeout = 100 * time.Millisecond
)

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
	// SkipErrors turns off error passing and allows UDS to emulate UDP behavior.
	SkipErrors bool
	// contains filtered or unexported fields
}

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

func New

func New(opts ...ConnOpt) (*Client, error)

New returns a new Client.

If no options are provided, metrics will be sent unbuffered to 127.0.0.1:8125.

func (*Client) Clone

func (c *Client) Clone() (*Client, error)

Clone creates a new client with the same settings.

This is useful to avoid lock contention between busy, long-running goroutines.

func (*Client) Close

func (c *Client) Close() error

Close the client connection.

func (*Client) Count

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

Count tracks how many times something happened per second.

func (*Client) Decr

func (c *Client) Decr(name string, rate float64, tags ...string) error

Decr is just Count of -1

func (*Client) Distribution

func (c *Client) Distribution(name string, value float64, rate float64, tags ...string) error

Distribution tracks the statistical distribution of a set of values across your infrastructure.

func (*Client) Event

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

Event sends the provided Event.

func (*Client) Flush

func (c *Client) Flush() error

Flush forces a flush of the pending commands in the buffer

func (*Client) Gauge

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

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

func (*Client) Histogram

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

Histogram tracks the statistical distribution of a set of values on each host.

func (*Client) Incr

func (c *Client) Incr(name string, rate float64, tags ...string) error

Incr is just Count of 1

func (*Client) ServiceCheck

func (c *Client) ServiceCheck(sc ServiceCheck) error

ServiceCheck sends the provided ServiceCheck.

func (*Client) Set

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

Set counts the number of unique elements in a group.

func (*Client) SetWriteTimeout

func (c *Client) SetWriteTimeout(d time.Duration) error

SetWriteTimeout allows the user to set a custom UDS write timeout. Not supported for UDP.

func (*Client) SimpleEvent

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

SimpleEvent sends an event with the provided title and text.

func (*Client) SimpleServiceCheck

func (c *Client) SimpleServiceCheck(name string, status ServiceCheckStatus) error

SimpleServiceCheck sends an serviceCheck with the provided name and status.

func (*Client) TimeInMilliseconds

func (c *Client) TimeInMilliseconds(name string, value float64, rate float64, tags ...string) 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)

func (*Client) Timing

func (c *Client) Timing(name string, value time.Duration, rate float64, tags ...string) error

Timing sends timing information, it is an alias for TimeInMilliseconds

type ConnOpt

type ConnOpt func(*Client) error

ConnOpt is a function for configuring a dogstatsd Client.

func ConnAddr

func ConnAddr(addr string) ConnOpt

ConnAddr configures the address to send metrics to.

func ConnBuffer

func ConnBuffer(size int) ConnOpt

ConnBuffer sets the maximum buffer size before sending to the server.

The dogstatsd_buffer_size option in the DataDog agent's config.yaml must be equal to or larger than the buffer size set here to prevent dropped/corrupted metrics.

The buffer size is additionally limited by the interface's MTU. Setting the buffer size larger than the MTU will result in a maximum buffer size equal to the MTU.

func ConnWriter

func ConnWriter(w Writer) ConnOpt

ConnWriter sets the writer to write statistics to.

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) ([]byte, 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.

type EventAlertType

type EventAlertType string

EventAlertType is the alert type for events

const (
	Info    EventAlertType = "info"
	Error   EventAlertType = "error"
	Warning EventAlertType = "warning"
	Success EventAlertType = "success"
)

Event alert types

type EventPriority

type EventPriority string

EventPriority is the event priority for events

const (
	Normal EventPriority = "normal"
	Low    EventPriority = "low"
)

Event Priorities

type ServiceCheck

type ServiceCheck struct {
	// Name of the service check. Required.
	Name string

	// Status of service check. Required.
	Status ServiceCheckStatus

	// Timestamp is a timestamp for the serviceCheck. If not provided, the dogstatsd
	// server will set this to the current time.
	Timestamp time.Time

	// Hostname for the serviceCheck.
	Hostname string

	// A message describing the current state of the serviceCheck.
	Message string

	// Tags for the serviceCheck.
	Tags []string
}

An ServiceCheck is an object that contains status of DataDog service check.

func NewServiceCheck

func NewServiceCheck(name string, status ServiceCheckStatus) ServiceCheck

NewServiceCheck creates a new serviceCheck with the given name and status. Error checking against these values is done at send-time, or upon running sc.Check.

func (ServiceCheck) Check

func (sc ServiceCheck) Check() error

Check verifies that an event is valid.

func (ServiceCheck) Encode

func (sc ServiceCheck) Encode(tags ...string) ([]byte, error)

Encode returns the dogstatsd wire protocol representation for an serviceCheck. 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.

type ServiceCheckStatus

type ServiceCheckStatus byte

ServiceCheckStatus support

const (
	Ok       ServiceCheckStatus = 0
	Warn     ServiceCheckStatus = 1
	Critical ServiceCheckStatus = 2
	Unknown  ServiceCheckStatus = 3
)

Service check statuses.

type Writer

type Writer interface {
	Write(data []byte) (n int, err error)
	SetWriteTimeout(time.Duration) error
	MTU() int
	Close() error
}

A Writer offers a standard interface regardless of the underlying protocol. For now UDS and UPD writers are available.

Jump to

Keyboard shortcuts

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