DDStats

package module
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 11 Imported by: 0

README

DDStats

DDStats is an non-DogStatsD client in Golang.

GoDoc

Example

package main

import (
	"github.com/jmizell/DDStats"
	"log"
)

func main() {

	// Initialize the client with your namespace, host, api key, and your global tags
	stats := DDStats.NewStats("namespace", "host", "api_key", []string{"custom_tag:true"})

	// We can add a new metric by calling any of the methods, Increment,
	// Decrement, Count or Gauge. Increment increases a count metric by one.
	stats.Increment("metric1", nil)

	// Custom tags will be combined with the global tags on send to the api.
	stats.Increment("metric2", []string{"tag:1"})

	// Decrement decreases a count metric by 1.
	stats.Decrement("metric1", nil)

	// Count allows you to add an arbitrary value to a count metric.
	stats.Count("metric1", 10, nil)

	// Adding tags metrics are unique by name, and tags. Metric1 with nil
	// tags, and metric1 with one custom tag, are stored as two separate values.
	stats.Count("metric1", 10, []string{"tag:1"})

	// Gauge creates a gauge metric. The last value applied to the metric before
	// flush to the api, is the value sent.
	stats.Gauge("metric3", 10, nil)

	// Signal shutdown, and block until complete
	stats.Close()

	// Get a list of errors returned by the api
	if errors := stats.Errors(); len(errors) > 0 {
		for i, err := range errors {
			log.Printf("%d: %s", i, err.Error())
		}
		log.Fatalf("errors were founc")
	}
}

Documentation

Index

Constants

View Source
const (
	Okay = iota
	Warning
	Critical
	Unknown
)

DDServiceCheck Status values

View Source
const (
	AlertError   = AlertType("error")
	AlertWarning = AlertType("warning")
	AlertInfo    = AlertType("info")
	AlertSuccess = AlertType("success")
)

DDEvent AlertType values

View Source
const (
	PriorityNormal = Priority("normal")
	PriorityLow    = Priority("low")
)

DDEvent Priority values

View Source
const (
	DefaultWorkerCount   = 10
	DefaultWorkerBuffer  = 100
	DefaultFlushInterval = time.Second * 60
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient interface {
	SendSeries(*DDMetricSeries) error
	SendServiceCheck(*DDServiceCheck) error
	SendEvent(*DDEvent) error
	SetHTTPClient(HTTPClient)
}

type AlertType

type AlertType string

type DDApiResponse

type DDApiResponse struct {
	Errors []string `json:"errors"`
}

type DDClient

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

func NewDDClient

func NewDDClient(apiKey string) *DDClient

func (*DDClient) SendEvent

func (c *DDClient) SendEvent(event *DDEvent) error

func (*DDClient) SendSeries

func (c *DDClient) SendSeries(series *DDMetricSeries) error

func (*DDClient) SendServiceCheck

func (c *DDClient) SendServiceCheck(check *DDServiceCheck) error

func (*DDClient) SetHTTPClient

func (c *DDClient) SetHTTPClient(client HTTPClient)

type DDEvent

type DDEvent struct {
	AggregationKey string    `json:"aggregation_key"`
	AlertType      AlertType `json:"alert_type"`
	DateHappened   int64     `json:"date_happened"`
	DeviceName     string    `json:"device_name"`
	Host           string    `json:"host"`
	Priority       Priority  `json:"priority"`
	RelatedEventID int64     `json:"related_event_id"`
	SourceTypeName string    `json:"source_type_name"`
	Tags           []string  `json:"tags"`
	Title          string    `json:"title"`
}

type DDMetric

type DDMetric struct {
	Host     string           `json:"host"`
	Interval int64            `json:"interval"`
	Metric   string           `json:"metric"`
	Points   [][2]interface{} `json:"points"`
	Tags     []string         `json:"tags"`
	Type     string           `json:"type"`
}

type DDMetricSeries

type DDMetricSeries struct {
	Series []*DDMetric `json:"series"`
}

type DDServiceCheck

type DDServiceCheck struct {
	Check     string   `json:"check"`
	Hostname  string   `json:"host_name"`
	Message   string   `json:"message"`
	Status    Status   `json:"status"`
	Tags      []string `json:"tags"`
	Timestamp int64    `json:"timestamp"`
}

type HTTPClient

type HTTPClient interface {
	Post(url, contentType string, body io.Reader) (resp *http.Response, err error)
}

type Priority

type Priority string

type Stats

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

func NewStats

func NewStats(namespace, host, apiKey string, tags []string) *Stats

func (*Stats) Close

func (c *Stats) Close()

Close signals a shutdown, and blocks while waiting for a final flush, and all workers to shutdown.

func (*Stats) Count

func (c *Stats) Count(name string, value float64, tags []string)

Count creates or adds a count metric by value. This is a non-blocking method, if the channel buffer is full, then the metric not recorded. Count stats are sent as rate, by taking the count value and dividing by the number of seconds since the last flush.

func (*Stats) Decrement

func (c *Stats) Decrement(name string, tags []string)

Decrement creates or subtracts a count metric by -1. This is a non-blocking method, if the channel buffer is full, then the metric not recorded. Count stats are sent as rate, by taking the count value and dividing by the number of seconds since the last flush.

func (*Stats) ErrorCallback

func (c *Stats) ErrorCallback(f func(err error))

ErrorCallback registers a call back function that will be called if any error is returned by the api client during a flush.

func (*Stats) Errors

func (c *Stats) Errors() []error

Errors returns a slice of all errors returned by the api client during a flush.

func (*Stats) Event

func (c *Stats) Event(event *DDEvent) error

Event immediately posts an DDEvent to he Datadog api. If host, or namespace vales are missing, the values will be filled before sending to the api. Global tags are appended to the event.

func (*Stats) Flush

func (c *Stats) Flush()

Flush signals the main worker thread to copy all current metrics, and send them to the Datadog api.

func (*Stats) FlushCallback

func (c *Stats) FlushCallback(f func(metrics map[string]*metric))

FlushCallback registers a call back function that will be called at the end of every successful flush.

func (*Stats) Gauge

func (c *Stats) Gauge(name string, value float64, tags []string)

Gauge creates or updates a gauge metric by value. This is a non-blocking method, if the channel buffer is full, then the metric not recorded. Gauge stats are reported as the last value sent before flush is called.

func (*Stats) Increment

func (c *Stats) Increment(name string, tags []string)

Increment creates or increments a count metric by +1. This is a non-blocking method, if the channel buffer is full, then the metric not recorded. Count stats are sent as rate, by taking the count value and dividing by the number of seconds since the last flush.

func (*Stats) SendSeries

func (c *Stats) SendSeries(series []*DDMetric) error

SendSeries immediately posts an DDMetric series to the Datadog api. Each metric in the series is checked for an host name, and the correct namespace. If host, or namespace vales are missing, the values will be filled before sending to the api. Global tags are added to all metrics.

func (*Stats) ServiceCheck

func (c *Stats) ServiceCheck(check, message string, status Status, tags []string) error

ServiceCheck immediately posts an DDServiceCheck to he Datadog api. The namespace is prepended to the check name, if it is missing. Host, and time is automatically added. Global tags are appended to tags passed to the method.

type Status

type Status int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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