datadog

package
v4.7.3 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// DefaultAddress is the default address to which the datadog client tries
	// to connect to.
	DefaultAddress = "localhost:8125"

	// DefaultBufferSize is the default size for batches of metrics sent to
	// datadog.
	DefaultBufferSize = 1024

	// MaxBufferSize is a hard-limit on the max size of the datagram buffer.
	MaxBufferSize = 65507
)

Variables

View Source
var (
	// DefaultFilters are the default tags to filter before sending to
	// datadog. Using the request path as a tag can overwhelm datadog's
	// servers if there are too many unique routes due to unique IDs being a
	// part of the path. Only change the default filters if there are a static
	// number of routes.
	DefaultFilters = []string{"http_req_path"}

	// DefaultDistributionPrefixes is the default set of name prefixes for
	// metrics to be sent as distributions instead of as histograms.
	DefaultDistributionPrefixes = []string{}
)

Functions

func ListenAndServe

func ListenAndServe(addr string, handler Handler) (err error)

ListenAndServe starts a new dogstatsd server, listening for UDP datagrams on addr and forwarding the metrics to handler.

func Serve

func Serve(conn net.PacketConn, handler Handler) error

Serve runs a dogstatsd server, listening for datagrams on conn and forwarding the metrics to handler.

Types

type Client

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

Client represents an datadog client that implements the stats.Handler interface.

func NewClient

func NewClient(addr string) *Client

NewClient creates and returns a new datadog client publishing metrics to the server running at addr.

func NewClientWith

func NewClientWith(config ClientConfig) *Client

NewClientWith creates and returns a new datadog client configured with the given config.

func (*Client) AppendMeasure added in v4.6.4

func (s *Client) AppendMeasure(b []byte, m stats.Measure) []byte

AppendMeasure is a formatting routine to append the dogstatsd protocol representation of a measure to a memory buffer. Tags listed in the s.filters are removed. (some tags may not be suitable for submission to DataDog) Histogram metrics will be sent as distribution type if the metric name matches s.distPrefixes DogStatsd Protocol Docs: https://docs.datadoghq.com/developers/dogstatsd/datagram_shell?tab=metrics#the-dogstatsd-protocol

func (*Client) AppendMeasures

func (s *Client) AppendMeasures(b []byte, _ time.Time, measures ...stats.Measure) []byte

func (*Client) Close

func (c *Client) Close() error

Close flushes and closes the client, satisfies the io.Closer interface.

func (*Client) Flush

func (c *Client) Flush()

Flush satisfies the stats.Flusher interface.

func (*Client) HandleMeasures

func (c *Client) HandleMeasures(time time.Time, measures ...stats.Measure)

HandleMeasures satisfies the stats.Handler interface.

func (*Client) Write

func (c *Client) Write(b []byte) (int, error)

Write satisfies the io.Writer interface.

type ClientConfig

type ClientConfig struct {
	// Address of the datadog database to send metrics to.
	Address string

	// Maximum size of batch of events sent to datadog.
	BufferSize int

	// List of tags to filter. If left nil is set to DefaultFilters.
	Filters []string

	// Set of name prefixes for metrics to be sent as distributions instead of
	// as histograms.
	DistributionPrefixes []string

	// UseDistributions True indicates to send histograms with `d` type instead of `h` type
	// https://docs.datadoghq.com/developers/dogstatsd/datagram_shell?tab=metrics#the-dogstatsd-protocol
	UseDistributions bool
}

The ClientConfig type is used to configure datadog clients.

type Event

type Event struct {
	Title          string
	Text           string
	Ts             int64
	Priority       EventPriority
	Host           string
	Tags           []stats.Tag
	AlertType      EventAlertType
	AggregationKey string
	SourceTypeName string
	EventType      string
}

Event is a representation of a datadog event.

func (Event) Format

func (e Event) Format(f fmt.State, _ rune)

Format satisfies the fmt.Formatter interface.

func (Event) String

func (e Event) String() string

String satisfies the fmt.Stringer interface.

type EventAlertType

type EventAlertType string

EventAlertType is an enumeration providing the available datadog event allert types.

const (
	EventAlertTypeError   EventAlertType = "error"
	EventAlertTypeWarning EventAlertType = "warning"
	EventAlertTypeInfo    EventAlertType = "info"
	EventAlertTypeSuccess EventAlertType = "success"
)

Event Alert Types.

type EventPriority

type EventPriority string

EventPriority is an enumeration providing the available datadog event priority levels.

const (
	EventPriorityNormal EventPriority = "normal"
	EventPriorityLow    EventPriority = "low"
)

Event Priorities.

type Handler

type Handler interface {
	// HandleMetric is called when a dogstatsd server receives a metric.
	// The method receives the metric and the address from which it was sent.
	HandleMetric(Metric, net.Addr)

	// HandleEvent is called when a dogstatsd server receives an event.
	// The method receives the metric and the address from which it was sent.
	HandleEvent(Event, net.Addr)
}

Handler defines the interface that types must satisfy to process metrics received by a dogstatsd server.

type HandlerFunc

type HandlerFunc func(Metric, net.Addr)

HandlerFunc makes it possible for function types to be used as metric handlers on dogstatsd servers.

func (HandlerFunc) HandleEvent

func (f HandlerFunc) HandleEvent(Event, net.Addr)

HandleEvent is a no-op for backwards compatibility.

func (HandlerFunc) HandleMetric

func (f HandlerFunc) HandleMetric(m Metric, a net.Addr)

HandleMetric calls f(m, a).

type Metric

type Metric struct {
	Type      MetricType  // the metric type
	Namespace string      // the metric namespace (never populated by parsing operations)
	Name      string      // the metric name
	Value     float64     // the metric value
	Rate      float64     // sample rate, a value between 0 and 1
	Tags      []stats.Tag // the list of tags set on the metric
}

The Metric type is a representation of the metrics supported by datadog.

func (Metric) Format

func (m Metric) Format(f fmt.State, _ rune)

Format satisfies the fmt.Formatter interface.

func (Metric) String

func (m Metric) String() string

String satisfies the fmt.Stringer interface.

type MetricType

type MetricType string

MetricType is an enumeration providing symbols to represent the different metric types supported by datadog.

const (
	Counter      MetricType = "c"
	Gauge        MetricType = "g"
	Histogram    MetricType = "h"
	Distribution MetricType = "d"
	Unknown      MetricType = "?"
)

Metric Types.

Jump to

Keyboard shortcuts

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