metrics

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: Apache-2.0 Imports: 24 Imported by: 17

README

Metrics

The agent offers different type of metric. Each metrics offers 2 methods addSample and flush.

  • addSample: add a new sample to the metrics.
  • flush: aggregate all samples received since the last flush and return a Series to be forwarded to the DataDog backend.
gauge

Gauge tracks the value of a metric. The last value received is the one returned by the flush method.

counter

Counter tracks how many times something happened per second. Counters are only used by DogStatsD and are very similar to Count: the main diffence is that they are sent as Rate.

count

Count is used to count the number of events that occur between 2 flushes. Each sample's value is added to the value that's flushed.

histogram

Histogram tracks the distribution of samples added over one flush period.

historate

Historate tracks the distribution of samples added over one flush period for "rate" like metrics. Warning this doesn't use the harmonic mean, beware of what it means when using it.

monotonic_count

MonotonicCount tracks a raw counter, based on increasing counter values. Samples that have a lower value than the previous sample are ignored (since it usually means that the underlying raw counter has been reset).

Example:

Submitting samples 2, 3, 6, 7 returns 5 (i.e. 7-2) on flush, then submitting samples 10, 11 on the same MonotonicCount returns 4 (i.e. 11-7) on the second flush.

percentile

Percentile tracks the distribution of samples added over one flush period. Designed to be globally accurate for percentiles.

Percentile is not usable yet; it is still undergoing development and testing.

rate

Rate tracks the rate of a metric over 2 successive flushes (ie: no metrics will be returned on the first flush).

set

Set tracks the number of unique elements in a set. This is only used by DogStatsD; you cannot create sets from an Agent check.

service_check

Service checks track the status of any service: OK, WARNING, CRITICAL, or UNKNOWN. The Agent does not aggregate service checks, it sends every check straight to Datadog's backend.

event

Events represent discrete moments in time, e.g. thrown exceptions, code deploys, etc. The Agent does not aggregate events, it sends every event straight to your Datadog event stream.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DistributionMetricTypes = map[MetricType]struct{}{
	DistributionType: {},
}

DistributionMetricTypes contains the MetricTypes that are used for percentiles

Functions

func AssertPointsEqual

func AssertPointsEqual(t *testing.T, expected, actual []Point)

AssertPointsEqual evaluate if two list of point are equal (order doesn't matters).

func AssertSerieEqual

func AssertSerieEqual(t *testing.T, expected, actual *Serie)

AssertSerieEqual evaluate if two are equal.

func AssertSeriesEqual

func AssertSeriesEqual(t *testing.T, expected Series, series Series)

AssertSeriesEqual evaluate if two list of series match

func AssertSketchSeriesApproxEqual

func AssertSketchSeriesApproxEqual(t assert.TestingT, exp, act SketchSeries, e float64)

AssertSketchSeriesApproxEqual checks whether two SketchSeries are approximately equal. e represents the acceptable error %

func AssertSketchSeriesEqual

func AssertSketchSeriesEqual(t assert.TestingT, exp, act SketchSeries)

AssertSketchSeriesEqual checks whether two SketchSeries are equal

func AssertTagsEqual

func AssertTagsEqual(t assert.TestingT, expected, actual []string)

AssertTagsEqual evaluate if two list of tags are equal (the order doesn't matters).

Types

type APIMetricType

type APIMetricType int

APIMetricType represents an API metric type

const (
	APIGaugeType APIMetricType = iota
	APIRateType
	APICountType
)

Enumeration of the existing API metric types

func (APIMetricType) MarshalText

func (a APIMetricType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshal interface to marshal an APIMetricType to a serialized byte slice

func (APIMetricType) String

func (a APIMetricType) String() string

String returns a string representation of APIMetricType

func (*APIMetricType) UnmarshalText

func (a *APIMetricType) UnmarshalText(buf []byte) error

UnmarshalText is a custom unmarshaller for APIMetricType (used for testing)

type ContextMetrics

type ContextMetrics map[ckey.ContextKey]Metric

ContextMetrics stores all the metrics by context key

func MakeContextMetrics

func MakeContextMetrics() ContextMetrics

MakeContextMetrics returns a new ContextMetrics

func (ContextMetrics) AddSample

func (m ContextMetrics) AddSample(contextKey ckey.ContextKey, sample *MetricSample, timestamp float64, interval int64) error

AddSample add a sample to the current ContextMetrics and initialize a new metrics if needed.

func (ContextMetrics) Flush

func (m ContextMetrics) Flush(timestamp float64) ([]*Serie, map[ckey.ContextKey]error)

Flush flushes every metrics in the ContextMetrics. Returns the slice of Series and a map of errors by context key.

type Count

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

Count is used to count the number of events that occur between 2 flushes. Each sample's value is added to the value that's flushed

type Counter

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

Counter tracks how many times something happened per second. Counters are only used by DogStatsD and are very similar to Count: the main diffence is that they are sent as Rate.

func NewCounter

func NewCounter(interval int64) *Counter

NewCounter return a new initialized Counter

type Event

type Event struct {
	Title          string         `json:"msg_title"`
	Text           string         `json:"msg_text"`
	Ts             int64          `json:"timestamp"`
	Priority       EventPriority  `json:"priority,omitempty"`
	Host           string         `json:"host"`
	Tags           []string       `json:"tags,omitempty"`
	AlertType      EventAlertType `json:"alert_type,omitempty"`
	AggregationKey string         `json:"aggregation_key,omitempty"`
	SourceTypeName string         `json:"source_type_name,omitempty"`
	EventType      string         `json:"event_type,omitempty"`
}

Event holds an event (w/ serialization to DD agent 5 intake format)

func (*Event) String

func (e *Event) String() string

Return a JSON string or "" in case of error during the Marshaling

type EventAlertType

type EventAlertType string

EventAlertType represents the alert type of an event

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

Enumeration of the existing event alert types, and their values

func GetAlertTypeFromString

func GetAlertTypeFromString(val string) (EventAlertType, error)

GetAlertTypeFromString returns the EventAlertType from its string representation

type EventPriority

type EventPriority string

EventPriority represents the priority of an event

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

Enumeration of the existing event priorities, and their values

func GetEventPriorityFromString

func GetEventPriorityFromString(val string) (EventPriority, error)

GetEventPriorityFromString returns the EventPriority from its string representation

type Events

type Events []*Event

Events represents a list of events ready to be serialize

func (Events) CreateMarshalersBySourceType

func (events Events) CreateMarshalersBySourceType() []marshaler.StreamJSONMarshaler

CreateMarshalersBySourceType creates a collection of marshaler.StreamJSONMarshaler. Each StreamJSONMarshaler is composed of all events for a specific source type name.

func (Events) CreateSingleMarshaler

func (events Events) CreateSingleMarshaler() marshaler.StreamJSONMarshaler

CreateSingleMarshaler creates marshaler.StreamJSONMarshaler where each item is composed of all events for a specific source type name.

func (Events) Marshal

func (events Events) Marshal() ([]byte, error)

Marshal serialize events using agent-payload definition

func (Events) MarshalJSON

func (events Events) MarshalJSON() ([]byte, error)

MarshalJSON serializes events to JSON so it can be sent to the Agent 5 intake (we don't use the v1 event endpoint because it only supports 1 event per payload) FIXME(olivier): to be removed when v2 endpoints are available

func (Events) SplitPayload

func (events Events) SplitPayload(times int) ([]marshaler.Marshaler, error)

SplitPayload breaks the payload into times number of pieces

type Gauge

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

Gauge tracks the value of a metric

type Histogram

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

Histogram tracks the distribution of samples added over one flush period

func NewHistogram

func NewHistogram(interval int64) *Histogram

NewHistogram returns a newly initialized histogram

type HistogramBucket

type HistogramBucket struct {
	Name       string
	Value      int64
	LowerBound float64
	UpperBound float64
	Monotonic  bool
	Tags       []string
	Host       string
	Timestamp  float64
}

HistogramBucket represents a prometheus/openmetrics histogram bucket

func (*HistogramBucket) GetHost

func (m *HistogramBucket) GetHost() string

GetHost returns the bucket host

func (*HistogramBucket) GetName

func (m *HistogramBucket) GetName() string

GetName returns the bucket name

func (*HistogramBucket) GetTags

func (m *HistogramBucket) GetTags() []string

GetTags returns the bucket tags

type Historate

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

Historate tracks the distribution of samples added over one flush period for "rate" like metrics. Warning this doesn't use the harmonic mean, beware of what it means when using it.

func NewHistorate

func NewHistorate(interval int64) *Historate

NewHistorate returns a newly-initialized historate

type Metric

type Metric interface {
	// contains filtered or unexported methods
}

Metric is the interface of all metric types

type MetricSample

type MetricSample struct {
	Name       string
	Value      float64
	RawValue   string
	Mtype      MetricType
	Tags       []string
	Host       string
	SampleRate float64
	Timestamp  float64
}

MetricSample represents a raw metric sample

func (*MetricSample) Copy

func (m *MetricSample) Copy() *MetricSample

Copy returns a deep copy of the m MetricSample

func (*MetricSample) GetHost

func (m *MetricSample) GetHost() string

GetHost returns the metric sample host

func (*MetricSample) GetName

func (m *MetricSample) GetName() string

GetName returns the metric sample name

func (*MetricSample) GetTags

func (m *MetricSample) GetTags() []string

GetTags returns the metric sample tags

type MetricSampleContext

type MetricSampleContext interface {
	GetName() string
	GetHost() string
	GetTags() []string
}

MetricSampleContext allows to access a sample context data

type MetricSamplePool

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

MetricSamplePool is a pool of metrics sample

func NewMetricSamplePool

func NewMetricSamplePool(batchSize int) *MetricSamplePool

NewMetricSamplePool creates a new MetricSamplePool

func (*MetricSamplePool) GetBatch

func (m *MetricSamplePool) GetBatch() []MetricSample

GetBatch gets a batch of metric samples from the pool

func (*MetricSamplePool) PutBatch

func (m *MetricSamplePool) PutBatch(batch []MetricSample)

PutBatch puts a batch back into the pool

type MetricType

type MetricType int

MetricType is the representation of an aggregator metric type

const (
	GaugeType MetricType = iota
	RateType
	CountType
	MonotonicCountType
	CounterType
	HistogramType
	HistorateType
	SetType
	// NOTE: DistributionType is in development and is NOT supported
	DistributionType
)

metric type constants enumeration

func (MetricType) String

func (m MetricType) String() string

String returns a string representation of MetricType

type MonotonicCount

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

MonotonicCount tracks a raw counter, based on increasing counter values. Samples that have a lower value than the previous sample are ignored (since it usually means that the underlying raw counter has been reset). Example:

submitting samples 2, 3, 6, 7 returns 5 (i.e. 7-2) on flush ;
then submitting samples 10, 11 on the same MonotonicCount returns 4 (i.e. 11-7) on flush

type NoSerieError

type NoSerieError struct{}

NoSerieError is the error returned by a metric when not enough samples have been submitted to generate a serie

func (NoSerieError) Error

func (e NoSerieError) Error() string

type Point

type Point struct {
	Ts    float64
	Value float64
}

Point represents a metric value at a specific time

func (*Point) MarshalJSON

func (p *Point) MarshalJSON() ([]byte, error)

MarshalJSON return a Point as an array of value (to be compatible with v1 API) FIXME(maxime): to be removed when v2 endpoints are available Note: it is not used with jsoniter, encodePoints takes over

func (*Point) UnmarshalJSON

func (p *Point) UnmarshalJSON(buf []byte) error

UnmarshalJSON is a custom unmarshaller for Point (used for testing)

type Rate

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

Rate tracks the rate of a metric over 2 successive flushes

type Serie

type Serie struct {
	Name           string          `json:"metric"`
	Points         []Point         `json:"points"`
	Tags           []string        `json:"tags"`
	Host           string          `json:"host"`
	Device         string          `json:"device,omitempty"` // FIXME(olivier): remove as soon as the v1 API can handle `device` as a regular tag
	MType          APIMetricType   `json:"type"`
	Interval       int64           `json:"interval"`
	SourceTypeName string          `json:"source_type_name,omitempty"`
	ContextKey     ckey.ContextKey `json:"-"`
	NameSuffix     string          `json:"-"`
}

Serie holds a timeseries (w/ json serialization to DD API format)

func (Serie) String

func (e Serie) String() string

String could be used for debug logging

type Series

type Series []*Serie

Series represents a list of Serie ready to be serialize

func (Series) DescribeItem

func (series Series) DescribeItem(i int) string

DescribeItem returns a text description for logs

func (Series) Len

func (series Series) Len() int

Len returns the number of items to marshal

func (Series) Marshal

func (series Series) Marshal() ([]byte, error)

Marshal serialize timeseries using agent-payload definition

func (Series) MarshalJSON

func (series Series) MarshalJSON() ([]byte, error)

MarshalJSON serializes timeseries to JSON so it can be sent to V1 endpoints FIXME(maxime): to be removed when v2 endpoints are available

func (Series) SplitPayload

func (series Series) SplitPayload(times int) ([]marshaler.Marshaler, error)

SplitPayload breaks the payload into, at least, "times" number of pieces

func (Series) WriteFooter

func (series Series) WriteFooter(stream *jsoniter.Stream) error

WriteFooter prints the payload footer for this type

func (Series) WriteHeader

func (series Series) WriteHeader(stream *jsoniter.Stream) error

WriteHeader writes the payload header for this type

func (Series) WriteItem

func (series Series) WriteItem(stream *jsoniter.Stream, i int) error

WriteItem prints the json representation of an item

type ServiceCheck

type ServiceCheck struct {
	CheckName string             `json:"check"`
	Host      string             `json:"host_name"`
	Ts        int64              `json:"timestamp"`
	Status    ServiceCheckStatus `json:"status"`
	Message   string             `json:"message"`
	Tags      []string           `json:"tags"`
}

ServiceCheck holds a service check (w/ serialization to DD api format)

func (ServiceCheck) String

func (sc ServiceCheck) String() string

type ServiceCheckStatus

type ServiceCheckStatus int

ServiceCheckStatus represents the status associated with a service check

const (
	ServiceCheckOK       ServiceCheckStatus = iota
	ServiceCheckWarning  ServiceCheckStatus = 1
	ServiceCheckCritical ServiceCheckStatus = 2
	ServiceCheckUnknown  ServiceCheckStatus = 3
)

Enumeration of the existing service check statuses, and their values

func GetServiceCheckStatus

func GetServiceCheckStatus(val int) (ServiceCheckStatus, error)

GetServiceCheckStatus returns the ServiceCheckStatus from and integer value

func (ServiceCheckStatus) String

func (s ServiceCheckStatus) String() string

String returns a string representation of ServiceCheckStatus

type ServiceChecks

type ServiceChecks []*ServiceCheck

ServiceChecks represents a list of service checks ready to be serialize

func (ServiceChecks) DescribeItem

func (sc ServiceChecks) DescribeItem(i int) string

DescribeItem returns a text description for logs

func (ServiceChecks) Len

func (sc ServiceChecks) Len() int

Len returns the number of items to marshal

func (ServiceChecks) Marshal

func (sc ServiceChecks) Marshal() ([]byte, error)

Marshal serialize service checks using agent-payload definition

func (ServiceChecks) MarshalJSON

func (sc ServiceChecks) MarshalJSON() ([]byte, error)

MarshalJSON serializes service checks to JSON so it can be sent to V1 endpoints FIXME(olivier): to be removed when v2 endpoints are available

func (ServiceChecks) SplitPayload

func (sc ServiceChecks) SplitPayload(times int) ([]marshaler.Marshaler, error)

SplitPayload breaks the payload into times number of pieces

func (ServiceChecks) WriteFooter

func (sc ServiceChecks) WriteFooter(stream *jsoniter.Stream) error

WriteFooter prints the payload footer for this type

func (ServiceChecks) WriteHeader

func (sc ServiceChecks) WriteHeader(stream *jsoniter.Stream) error

WriteHeader writes the payload header for this type

func (ServiceChecks) WriteItem

func (sc ServiceChecks) WriteItem(stream *jsoniter.Stream, i int) error

WriteItem prints the json representation of an item

type Set

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

Set tracks the number of unique elements in a set. They are only use by DogStatsD

func NewSet

func NewSet() *Set

NewSet return a new initialized Set

type SketchPoint

type SketchPoint struct {
	Sketch *quantile.Sketch `json:"sketch"`
	Ts     int64            `json:"ts"`
}

A SketchPoint represents a quantile sketch at a specific time

type SketchSeries

type SketchSeries struct {
	Name       string          `json:"metric"`
	Tags       []string        `json:"tags"`
	Host       string          `json:"host"`
	Interval   int64           `json:"interval"`
	Points     []SketchPoint   `json:"points"`
	ContextKey ckey.ContextKey `json:"-"`
}

A SketchSeries is a timeseries of quantile sketches.

type SketchSeriesList

type SketchSeriesList []SketchSeries

A SketchSeriesList implements marshaler.Marshaler

func (SketchSeriesList) Marshal

func (sl SketchSeriesList) Marshal() ([]byte, error)

Marshal encodes this series list.

func (SketchSeriesList) MarshalJSON

func (sl SketchSeriesList) MarshalJSON() ([]byte, error)

MarshalJSON serializes sketch series to JSON. Quite slow, but hopefully this method is called only in the `agent check` command

func (SketchSeriesList) SplitPayload

func (sl SketchSeriesList) SplitPayload(times int) ([]marshaler.Marshaler, error)

SplitPayload breaks the payload into times number of pieces

Jump to

Keyboard shortcuts

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