datadog

package module
v0.0.0-...-a35917e Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2015 License: MIT Imports: 8 Imported by: 0

README

Go Datadog

Simple Go interface to the Datadog API.

Metrics

The client can report metrics from go-metrics. Using either its DefaultRegistry, or a custom one, metrics can be periodically sent with code along the lines of the following:

import(
  "github.com/vistarmedia/datadog"
  "os"
  "time"
)

host _ := os.Hostname()
dog := datadog.New(host, "dog-api-key")
go dog.DefaultReporter().Start(60 * time.Second)

And to use a custom registry, it would simply read:

host _ := os.Hostname()
dog := datadog.New(host, "dog-api-key")
reporter := getMyCustomRegistry()
go dog.Reporter(registry).Start(60 * time.Second)

Documentation

Overview

Simple client to the [Datadog API](http://docs.datadoghq.com/api/).

Datadog reporter for the [go-metrics](https://github.com/rcrowley/go-metrics) library.

Index

Constants

View Source
const (
	ENDPOINT        = "https://app.datadoghq.com/api"
	SERIES_ENDPIONT = "/v1/series"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host   string
	ApiKey string
}

func New

func New(host, apiKey string) *Client

Create a new Datadog client. In EC2, datadog expects the hostname to be the instance ID rather than `gethostname(2)`. However, that value can be obtained with `os.Hostname()`.

func (*Client) DefaultReporter

func (c *Client) DefaultReporter() *MetricsReporter

Create a `MetricsReporter` configured to use metric's default registry. This reporter will not be started.

func (*Client) PostSeries

func (c *Client) PostSeries(series []*Series) (err error)

Posts an array of series data to the Datadog API. The API expects an object, not an array, so it will be wrapped in a `seriesMessage` with a single `series` field.

func (*Client) Reporter

func (c *Client) Reporter(reg metrics.Registry) *MetricsReporter

Create a `MetricsReporter` for the given metrics reporter. The returned reporter will not be started.

func (*Client) SeriesUrl

func (c *Client) SeriesUrl() string

Gets an authenticated URL to POST series data to. In Datadog's examples, this value is 'https://app.datadoghq.com/api/v1/series?api_key=9775a026f1ca7d1...'

type MetricsReporter

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

func Reporter

func Reporter(c *Client, r metrics.Registry) *MetricsReporter

Create an un-started MetricsReporter. In most circumstances, the `metrics.DefaultRegistry` will suffice for the required `metrics.Registry`. The recreated `MetricsReporter` will not be started. Invoke `go r.Start(..)` with a `time.Duration` to enable reporting.

func (*MetricsReporter) Report

func (mr *MetricsReporter) Report() error

POST a single series report to the Datadog API. A 200 or 202 is expected for this to complete without error.

func (*MetricsReporter) Series

func (mr *MetricsReporter) Series() []*Series

For each metric assocaited with the current Registry, convert it to a `Series` message, and return them all as a single array. The series messages will have the current hostname of the `Client`.

func (*MetricsReporter) Start

func (mr *MetricsReporter) Start(d time.Duration)

Start this reporter in a blocking fashion, pushing series data to datadog at the specified interval. If any errors occur, they will be logged to the default logger, and further updates will continue.

Scheduling is done with a `time.Ticker`, so non-overlapping intervals are absolute, not based on the finish time of the previous event. They are, however, serial.

type Series

type Series struct {
	Metric string           `json:"metric"`
	Points [][2]interface{} `json:"points"`
	Type   string           `json:"type"`
	Host   string           `json:"host"`
	Tags   []string         `json:"tags,omitempty"`
}

Jump to

Keyboard shortcuts

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