metrics

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: Apache-2.0 Imports: 12 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddProcessor

func AddProcessor(ctx context.Context, processor Processor) context.Context

AddProcessor adds a processor to a context object

Types

type APIClient

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

APIClient send metrics to Datadog, via the Datadog API

func MakeAPIClient

func MakeAPIClient(ctx context.Context, baseAPIURL, apiKey string) *APIClient

MakeAPIClient creates a new API client with the given api and app keys

func (*APIClient) PrewarmConnection

func (cl *APIClient) PrewarmConnection() error

PrewarmConnection sends a redundant GET request to the Datadog API to prewarm the TSL connection

func (*APIClient) SendMetrics

func (cl *APIClient) SendMetrics(metrics []APIMetric) error

SendMetrics posts a batch metrics payload to the Datadog API

type APIMetric

type APIMetric struct {
	Name       string        `json:"metric"`
	Host       *string       `json:"host,omitempty"`
	Tags       []string      `json:"tags,omitempty"`
	MetricType MetricType    `json:"type"`
	Interval   *float64      `json:"interval,omitempty"`
	Points     []interface{} `json:"points"`
}

APIMetric is a metric that can be marshalled to send to the metrics API

type BatchKey

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

BatchKey identifies a batch of metrics

type Batcher

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

Batcher aggregates metrics with common properties,(metric name, tags, type etc)

func MakeBatcher

func MakeBatcher(batchInterval time.Duration) *Batcher

MakeBatcher creates a new batcher object

func (*Batcher) AddMetric

func (b *Batcher) AddMetric(metric Metric)

AddMetric adds a point to a given metric

func (*Batcher) ToAPIMetrics

func (b *Batcher) ToAPIMetrics() []APIMetric

ToAPIMetrics converts the current batch of metrics into API metrics

type Client

type Client interface {
	SendMetrics(metrics []APIMetric) error
}

Client sends metrics to Datadog

type Config

type Config struct {
	APIKey               string
	Site                 string
	ShouldRetryOnFailure bool
	BatchInterval        time.Duration
}

Config gives options for how the listener should work

type Distribution

type Distribution struct {
	Name   string
	Tags   []string
	Host   *string
	Values []MetricValue
}

Distribution is a type of metric that is aggregated over multiple hosts

func (*Distribution) AddPoint

func (d *Distribution) AddPoint(timestamp time.Time, value float64)

AddPoint adds a point to the distribution metric

func (*Distribution) Join

func (d *Distribution) Join(metric Metric)

Join creates a union between two metric sets

func (*Distribution) ToAPIMetric

func (d *Distribution) ToAPIMetric(interval time.Duration) []APIMetric

ToAPIMetric converts a distribution into an API ready format.

func (*Distribution) ToBatchKey

func (d *Distribution) ToBatchKey() BatchKey

ToBatchKey returns a key that can be used to batch the metric

type Listener

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

Listener implements wrapper.HandlerListener, injecting metrics into the context

func MakeListener

func MakeListener(config Config) Listener

MakeListener initializes a new metrics lambda listener

func (*Listener) HandlerFinished

func (l *Listener) HandlerFinished(ctx context.Context)

HandlerFinished implemented as part of the wrapper.HandlerListener interface

func (*Listener) HandlerStarted

func (l *Listener) HandlerStarted(ctx context.Context, msg json.RawMessage) context.Context

HandlerStarted adds metrics service to the context

type Metric

type Metric interface {
	AddPoint(timestamp time.Time, value float64)
	ToAPIMetric(interval time.Duration) []APIMetric
	ToBatchKey() BatchKey
	Join(metric Metric)
}

Metric represents a metric that can have any kind of

type MetricType

type MetricType string

MetricType enumerates all the available metric types

const (

	// DistributionType represents a distribution metric
	DistributionType MetricType = "distribution"
)

type MetricValue added in v0.2.0

type MetricValue struct {
	Value     float64
	Timestamp time.Time
}

MetricValue represents a datapoint for a metric

type Processor

type Processor interface {
	// AddMetric sends a metric to the agent
	AddMetric(metric Metric)
	// StartProcessing begins processing metrics asynchronously
	StartProcessing()
	// FinishProcessing shuts down the agent, and tries to flush any remaining metrics
	FinishProcessing()
}

Processor is used to batch metrics on a background thread, and send them on to a client periodically.

func GetProcessor

func GetProcessor(ctx context.Context) Processor

GetProcessor retrieves the processor from a context object.

func MakeProcessor

func MakeProcessor(ctx context.Context, client Client, timeService TimeService, batchInterval time.Duration, shouldRetryOnFail bool) Processor

MakeProcessor creates a new metrics context

type TimeService

type TimeService interface {
	NewTicker(duration time.Duration) *time.Ticker
	Now() time.Time
}

TimeService wraps common time related operations

func MakeTimeService

func MakeTimeService() TimeService

MakeTimeService creates a new time service

Jump to

Keyboard shortcuts

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