metrics

package module
v0.0.0-...-13248f9 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 18 Imported by: 1

Documentation

Overview

package metrics wraps github.com/DataDog/datadog-go/v5/statsd with a more ergonomic and computationally cheaper interface.

This is done by separating tags from logging metrics so that for frequently-logged gauges and counters logging is just a single atomic operation.

For each metric type of Gauge, Count, Distribution, and Set, there are a set of NewMDefY methods where M is the metric type and Y is the number of tags. Calls to NewMDefY must be done at init-time (ideally in a top-level var block) of a metrics.go file with names as full literals so that metrics are easily greppable. Metrics not defined this way will cause the process to panic if still at init-time, meaning before any code in main() has run, otherwise will produce non-functional stats and produce to a gauge stat called metrics.bad_metric_definitions. It's a good idea to put an alert on this stat so that if it starts logging during a deploy, you know your other metrics may not be trustworthy.

See the example folder for an example of usage.

Generally you will have:

  1. metrics.NewMDefY calls in a top-level var block of metrics.go in packages that log metrics, named ending in "Def".
  2. metrics.New() in main(), passed down through constructors.
  3. At the point of logging metrics, e.g. m.Counter(myCounterDef.Values(tag1, tag2)).Add(1)

bad_metric_definitions reasons

  • not_at_init_time: The call to NewMDefY did not happen at init time (in either a top-level var block or func init()).
  • runtime_caller_failed: runtime.Caller returned false in its final return trying to evaluate the above.
  • observe_duration_bad_units: Distribution.ObserveDuration was used on a def that did not have compatible units. See the comment on Distribution.ObserveDuration.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	NoOpMetrics = &Metrics{
		p:       noOpPublisher{},
		bg:      xsync.NewGroup(context.Background()),
		flushed: make(chan struct{}),
		polls:   make(map[int]func()),
	}
)

Functions

func Defs

func Defs() map[string]Metadata

Defs returns metadata about all of the metric definitions in this process.

Since metrics are registered during init-time, this should be called only after main() has already begun.

func DumpDefs

func DumpDefs() error

DumpDefs prints JSON-formatted metadata about all of the metrics defined in this process to stdout.

Since metrics are registered during init-time, this should be called only after main() has already begun.

func ExponentialBuckets

func ExponentialBuckets(start float64, base float64, n int) []float64

ExponentialBuckets returns exponentially-increasing bucket boundaries for use with NewBucketedCounter and NewBucketedGaugeGroup.

start is the first value, base is the base of the exponent, and n is the number of boundaries.

Example
package main

import (
	"fmt"

	"github.com/bradenaw/metrics"
)

func main() {
	buckets := metrics.ExponentialBuckets(100, 10, 3)
	fmt.Println("ExponentialBuckets(100, 10, 3) ->", buckets)

	buckets = metrics.ExponentialBuckets(100, 2, 5)
	fmt.Println("ExponentialBuckets(100, 2, 5) ->", buckets)

}
Output:

ExponentialBuckets(100, 10, 3) -> [100 1000 10000]
ExponentialBuckets(100, 2, 5) -> [100 200 400 800 1600]

func LinearBuckets

func LinearBuckets(start float64, step float64, n int) []float64

LinearBuckets returns linearly-increasing bucket boundaries for use with NewBucketedCounter and NewBucketedGaugeGroup.

start is the first value, step is the distance between values, and n is the number of boundaries.

Example
package main

import (
	"fmt"

	"github.com/bradenaw/metrics"
)

func main() {
	buckets := metrics.LinearBuckets(100, 50, 3)
	fmt.Println("LinearBuckets(100, 50, 3) ->", buckets)

	buckets = metrics.LinearBuckets(100, 75, 4)
	fmt.Println("LinearBuckets(100, 75, 4) ->", buckets)

}
Output:

LinearBuckets(100, 50, 3) -> [100 150 200]
LinearBuckets(100, 75, 4) -> [100 175 250 325]

Types

type BucketedCounter

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

BucketedCounter is a counter sectioned into buckets.

For example, with boundaries []float64{100, 200, 400}, BucketedCounter will produce four counters with the following tag values:

lt_100             which counts Observe()s with v < 100
gte_100_lt_200     which counts Observe()s with 100 <= v < 200
gte_200_lt_400     which counts Observe()s with 200 <= v < 400
gte_400            which counts Observe()s with 400 <= v

func NewBucketedCounter

func NewBucketedCounter(
	m *Metrics,
	d CounterDef1[string],
	boundaries []float64,
) *BucketedCounter

NewBucketedCounter returns a counter that keeps track of observed values between the given boundaries.

By convention, the key for d is "bucket."

Boundaries must be in increasing order.

func (*BucketedCounter) Observe

func (b *BucketedCounter) Observe(v float64)

type BucketedGaugeGroup

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

BucketedGaugeGroup is a group of gauges sectioned by buckets of observed values. This is useful for measuring the state of the system in the number of items that fall into each bucket.

For example, if your process has a set of buffers that grow and shrink, you might be curious how many of each exist and what size each of them are. A good summary would be the number of buffers that are 1KB or less, 1KB-10KB, and 10KB-100KB, and 100KB+. This can be achieved by using a BucketedGaugeGroup with bucket boundaries [1024, 10*1024, 100*1024], which will produce four gauges with the following tag values:

lt_1024              which counts Observe()s since the last Emit() with v < 1024
gte_1024_lt_10240    which counts Observe()s since the last Emit() with 1024 <= v < 10240
gte_10240_lt_102400  which counts Observe()s since the last Emit() with 10240 <= v < 102400
gte_102400           which counts Observe()s since the last Emit() with 102400 <= v

BucketedGaugeGroups are usually emitted to using Metrics.EveryFlush.

func NewBucketedGaugeGroup

func NewBucketedGaugeGroup(
	m *Metrics,
	d GaugeDef1[string],
	boundaries []float64,
) *BucketedGaugeGroup

NewBucketedGaugeGroup returns a group of gauges that will emit the number of observations in each bucket.

By convention, the key for d is "bucket."

Boundaries must be in sorted order.

func (*BucketedGaugeGroup) Emit

func (gg *BucketedGaugeGroup) Emit()

Emit emits the observations passed to Observe() since the last Emit() as gauges.

func (*BucketedGaugeGroup) Observe

func (gg *BucketedGaugeGroup) Observe(v float64)

Observe adds one to the bucket that v falls in.

type Counter

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

Counter is a metric that keeps track of the number of events that happen per time interval.

Counters are good for measuring the rate of events, for example requests per second, or measuring the ratio between events by using tags, such as error rate.

func (*Counter) Add

func (c *Counter) Add(n int64)

type CounterDef

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

func NewCounterDef

func NewCounterDef(
	name string,
	description string,
	unit Unit,
) CounterDef

type CounterDef1

type CounterDef1[V0 TagValue] struct {
	// contains filtered or unexported fields
}

CounterDef1 is the definition of a counter metric with 1 tag(s).

func NewCounterDef1

func NewCounterDef1[V0 TagValue](
	name string,
	description string,
	unit Unit,
	keys [1]string,

) CounterDef1[V0]

NewCounterDef1 defines a counter metric with 1 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (CounterDef1[V0]) Values

func (d CounterDef1[V0]) Values(v0 V0) CounterDef

Values returns a CounterDef that has all of the given tag values bound. It can be passed to Metrics.Counter() to produce a metric to log data to.

type CounterDef2

type CounterDef2[V0 TagValue, V1 TagValue] struct {
	// contains filtered or unexported fields
}

CounterDef2 is the definition of a counter metric with 2 tag(s).

func NewCounterDef2

func NewCounterDef2[V0 TagValue, V1 TagValue](
	name string,
	description string,
	unit Unit,
	keys [2]string,

) CounterDef2[V0, V1]

NewCounterDef2 defines a counter metric with 2 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (CounterDef2[V0, V1]) Prefix1

func (d CounterDef2[V0, V1]) Prefix1(v0 V0) CounterDef1[V1]

Prefix1 sets the value of the first 1 tags, returning a CounterDef1 that can be used to set the rest.

func (CounterDef2[V0, V1]) Values

func (d CounterDef2[V0, V1]) Values(v0 V0, v1 V1) CounterDef

Values returns a CounterDef that has all of the given tag values bound. It can be passed to Metrics.Counter() to produce a metric to log data to.

type CounterDef3

type CounterDef3[V0 TagValue, V1 TagValue, V2 TagValue] struct {
	// contains filtered or unexported fields
}

CounterDef3 is the definition of a counter metric with 3 tag(s).

func NewCounterDef3

func NewCounterDef3[V0 TagValue, V1 TagValue, V2 TagValue](
	name string,
	description string,
	unit Unit,
	keys [3]string,

) CounterDef3[V0, V1, V2]

NewCounterDef3 defines a counter metric with 3 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (CounterDef3[V0, V1, V2]) Prefix1

func (d CounterDef3[V0, V1, V2]) Prefix1(v0 V0) CounterDef2[V1, V2]

Prefix1 sets the value of the first 1 tags, returning a CounterDef2 that can be used to set the rest.

func (CounterDef3[V0, V1, V2]) Prefix2

func (d CounterDef3[V0, V1, V2]) Prefix2(v0 V0, v1 V1) CounterDef1[V2]

Prefix2 sets the value of the first 2 tags, returning a CounterDef1 that can be used to set the rest.

func (CounterDef3[V0, V1, V2]) Values

func (d CounterDef3[V0, V1, V2]) Values(v0 V0, v1 V1, v2 V2) CounterDef

Values returns a CounterDef that has all of the given tag values bound. It can be passed to Metrics.Counter() to produce a metric to log data to.

type CounterDef4

type CounterDef4[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue] struct {
	// contains filtered or unexported fields
}

CounterDef4 is the definition of a counter metric with 4 tag(s).

func NewCounterDef4

func NewCounterDef4[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue](
	name string,
	description string,
	unit Unit,
	keys [4]string,

) CounterDef4[V0, V1, V2, V3]

NewCounterDef4 defines a counter metric with 4 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (CounterDef4[V0, V1, V2, V3]) Prefix1

func (d CounterDef4[V0, V1, V2, V3]) Prefix1(v0 V0) CounterDef3[V1, V2, V3]

Prefix1 sets the value of the first 1 tags, returning a CounterDef3 that can be used to set the rest.

func (CounterDef4[V0, V1, V2, V3]) Prefix2

func (d CounterDef4[V0, V1, V2, V3]) Prefix2(v0 V0, v1 V1) CounterDef2[V2, V3]

Prefix2 sets the value of the first 2 tags, returning a CounterDef2 that can be used to set the rest.

func (CounterDef4[V0, V1, V2, V3]) Prefix3

func (d CounterDef4[V0, V1, V2, V3]) Prefix3(v0 V0, v1 V1, v2 V2) CounterDef1[V3]

Prefix3 sets the value of the first 3 tags, returning a CounterDef1 that can be used to set the rest.

func (CounterDef4[V0, V1, V2, V3]) Values

func (d CounterDef4[V0, V1, V2, V3]) Values(v0 V0, v1 V1, v2 V2, v3 V3) CounterDef

Values returns a CounterDef that has all of the given tag values bound. It can be passed to Metrics.Counter() to produce a metric to log data to.

type CounterDef5

type CounterDef5[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue, V4 TagValue] struct {
	// contains filtered or unexported fields
}

CounterDef5 is the definition of a counter metric with 5 tag(s).

func NewCounterDef5

func NewCounterDef5[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue, V4 TagValue](
	name string,
	description string,
	unit Unit,
	keys [5]string,

) CounterDef5[V0, V1, V2, V3, V4]

NewCounterDef5 defines a counter metric with 5 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (CounterDef5[V0, V1, V2, V3, V4]) Prefix1

func (d CounterDef5[V0, V1, V2, V3, V4]) Prefix1(v0 V0) CounterDef4[V1, V2, V3, V4]

Prefix1 sets the value of the first 1 tags, returning a CounterDef4 that can be used to set the rest.

func (CounterDef5[V0, V1, V2, V3, V4]) Prefix2

func (d CounterDef5[V0, V1, V2, V3, V4]) Prefix2(v0 V0, v1 V1) CounterDef3[V2, V3, V4]

Prefix2 sets the value of the first 2 tags, returning a CounterDef3 that can be used to set the rest.

func (CounterDef5[V0, V1, V2, V3, V4]) Prefix3

func (d CounterDef5[V0, V1, V2, V3, V4]) Prefix3(v0 V0, v1 V1, v2 V2) CounterDef2[V3, V4]

Prefix3 sets the value of the first 3 tags, returning a CounterDef2 that can be used to set the rest.

func (CounterDef5[V0, V1, V2, V3, V4]) Prefix4

func (d CounterDef5[V0, V1, V2, V3, V4]) Prefix4(v0 V0, v1 V1, v2 V2, v3 V3) CounterDef1[V4]

Prefix4 sets the value of the first 4 tags, returning a CounterDef1 that can be used to set the rest.

func (CounterDef5[V0, V1, V2, V3, V4]) Values

func (d CounterDef5[V0, V1, V2, V3, V4]) Values(v0 V0, v1 V1, v2 V2, v3 V3, v4 V4) CounterDef

Values returns a CounterDef that has all of the given tag values bound. It can be passed to Metrics.Counter() to produce a metric to log data to.

type Distribution

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

Distribution produces quantile metrics, e.g. 50th, 90th, 99th percentiles of the values passed to Observe for each time bucket.

func (*Distribution) Observe

func (d *Distribution) Observe(value float64)

func (*Distribution) ObserveDuration

func (d *Distribution) ObserveDuration(value time.Duration)

As long as d's units are in nanoseconds, microseconds, milliseconds, seconds, minutes, or hours, records the given duration in the correct units.

Days and weeks are not supported, because not all days are the same length - in parts of the world that observe daylight savings, one day of the year is 25 hours and another is 23. As such, a time.Duration is not enough information to know days nor weeks so those must be recorded differently.

Other units will record nothing, but will emit a metrics.bad_metrics_definitions with reason:observe_duration_bad_units.

type DistributionDef

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

func NewDistributionDef

func NewDistributionDef(
	name string,
	description string,
	unit Unit,
	sampleRate float64,
) DistributionDef

type DistributionDef1

type DistributionDef1[V0 TagValue] struct {
	// contains filtered or unexported fields
}

DistributionDef1 is the definition of a distribution metric with 1 tag(s).

func NewDistributionDef1

func NewDistributionDef1[V0 TagValue](
	name string,
	description string,
	unit Unit,
	keys [1]string,
	sampleRate float64,
) DistributionDef1[V0]

NewDistributionDef1 defines a distribution metric with 1 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (DistributionDef1[V0]) Values

func (d DistributionDef1[V0]) Values(v0 V0) DistributionDef

Values returns a DistributionDef that has all of the given tag values bound. It can be passed to Metrics.Distribution() to produce a metric to log data to.

type DistributionDef2

type DistributionDef2[V0 TagValue, V1 TagValue] struct {
	// contains filtered or unexported fields
}

DistributionDef2 is the definition of a distribution metric with 2 tag(s).

func NewDistributionDef2

func NewDistributionDef2[V0 TagValue, V1 TagValue](
	name string,
	description string,
	unit Unit,
	keys [2]string,
	sampleRate float64,
) DistributionDef2[V0, V1]

NewDistributionDef2 defines a distribution metric with 2 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (DistributionDef2[V0, V1]) Prefix1

func (d DistributionDef2[V0, V1]) Prefix1(v0 V0) DistributionDef1[V1]

Prefix1 sets the value of the first 1 tags, returning a DistributionDef1 that can be used to set the rest.

func (DistributionDef2[V0, V1]) Values

func (d DistributionDef2[V0, V1]) Values(v0 V0, v1 V1) DistributionDef

Values returns a DistributionDef that has all of the given tag values bound. It can be passed to Metrics.Distribution() to produce a metric to log data to.

type DistributionDef3

type DistributionDef3[V0 TagValue, V1 TagValue, V2 TagValue] struct {
	// contains filtered or unexported fields
}

DistributionDef3 is the definition of a distribution metric with 3 tag(s).

func NewDistributionDef3

func NewDistributionDef3[V0 TagValue, V1 TagValue, V2 TagValue](
	name string,
	description string,
	unit Unit,
	keys [3]string,
	sampleRate float64,
) DistributionDef3[V0, V1, V2]

NewDistributionDef3 defines a distribution metric with 3 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (DistributionDef3[V0, V1, V2]) Prefix1

func (d DistributionDef3[V0, V1, V2]) Prefix1(v0 V0) DistributionDef2[V1, V2]

Prefix1 sets the value of the first 1 tags, returning a DistributionDef2 that can be used to set the rest.

func (DistributionDef3[V0, V1, V2]) Prefix2

func (d DistributionDef3[V0, V1, V2]) Prefix2(v0 V0, v1 V1) DistributionDef1[V2]

Prefix2 sets the value of the first 2 tags, returning a DistributionDef1 that can be used to set the rest.

func (DistributionDef3[V0, V1, V2]) Values

func (d DistributionDef3[V0, V1, V2]) Values(v0 V0, v1 V1, v2 V2) DistributionDef

Values returns a DistributionDef that has all of the given tag values bound. It can be passed to Metrics.Distribution() to produce a metric to log data to.

type DistributionDef4

type DistributionDef4[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue] struct {
	// contains filtered or unexported fields
}

DistributionDef4 is the definition of a distribution metric with 4 tag(s).

func NewDistributionDef4

func NewDistributionDef4[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue](
	name string,
	description string,
	unit Unit,
	keys [4]string,
	sampleRate float64,
) DistributionDef4[V0, V1, V2, V3]

NewDistributionDef4 defines a distribution metric with 4 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (DistributionDef4[V0, V1, V2, V3]) Prefix1

func (d DistributionDef4[V0, V1, V2, V3]) Prefix1(v0 V0) DistributionDef3[V1, V2, V3]

Prefix1 sets the value of the first 1 tags, returning a DistributionDef3 that can be used to set the rest.

func (DistributionDef4[V0, V1, V2, V3]) Prefix2

func (d DistributionDef4[V0, V1, V2, V3]) Prefix2(v0 V0, v1 V1) DistributionDef2[V2, V3]

Prefix2 sets the value of the first 2 tags, returning a DistributionDef2 that can be used to set the rest.

func (DistributionDef4[V0, V1, V2, V3]) Prefix3

func (d DistributionDef4[V0, V1, V2, V3]) Prefix3(v0 V0, v1 V1, v2 V2) DistributionDef1[V3]

Prefix3 sets the value of the first 3 tags, returning a DistributionDef1 that can be used to set the rest.

func (DistributionDef4[V0, V1, V2, V3]) Values

func (d DistributionDef4[V0, V1, V2, V3]) Values(v0 V0, v1 V1, v2 V2, v3 V3) DistributionDef

Values returns a DistributionDef that has all of the given tag values bound. It can be passed to Metrics.Distribution() to produce a metric to log data to.

type DistributionDef5

type DistributionDef5[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue, V4 TagValue] struct {
	// contains filtered or unexported fields
}

DistributionDef5 is the definition of a distribution metric with 5 tag(s).

func NewDistributionDef5

func NewDistributionDef5[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue, V4 TagValue](
	name string,
	description string,
	unit Unit,
	keys [5]string,
	sampleRate float64,
) DistributionDef5[V0, V1, V2, V3, V4]

NewDistributionDef5 defines a distribution metric with 5 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (DistributionDef5[V0, V1, V2, V3, V4]) Prefix1

func (d DistributionDef5[V0, V1, V2, V3, V4]) Prefix1(v0 V0) DistributionDef4[V1, V2, V3, V4]

Prefix1 sets the value of the first 1 tags, returning a DistributionDef4 that can be used to set the rest.

func (DistributionDef5[V0, V1, V2, V3, V4]) Prefix2

func (d DistributionDef5[V0, V1, V2, V3, V4]) Prefix2(v0 V0, v1 V1) DistributionDef3[V2, V3, V4]

Prefix2 sets the value of the first 2 tags, returning a DistributionDef3 that can be used to set the rest.

func (DistributionDef5[V0, V1, V2, V3, V4]) Prefix3

func (d DistributionDef5[V0, V1, V2, V3, V4]) Prefix3(v0 V0, v1 V1, v2 V2) DistributionDef2[V3, V4]

Prefix3 sets the value of the first 3 tags, returning a DistributionDef2 that can be used to set the rest.

func (DistributionDef5[V0, V1, V2, V3, V4]) Prefix4

func (d DistributionDef5[V0, V1, V2, V3, V4]) Prefix4(v0 V0, v1 V1, v2 V2, v3 V3) DistributionDef1[V4]

Prefix4 sets the value of the first 4 tags, returning a DistributionDef1 that can be used to set the rest.

func (DistributionDef5[V0, V1, V2, V3, V4]) Values

func (d DistributionDef5[V0, V1, V2, V3, V4]) Values(v0 V0, v1 V1, v2 V2, v3 V3, v4 V4) DistributionDef

Values returns a DistributionDef that has all of the given tag values bound. It can be passed to Metrics.Distribution() to produce a metric to log data to.

type Gauge

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

Gauge is a metric that reports the last value that it was set to.

Unlike Datadog's native gauge in the statsd client, Gauges report this value until the end of the process or until explicitly Unset().

Gauges are good for measuring states, for example the number of open connections or the size of a buffer.

func (*Gauge) Add

func (g *Gauge) Add(v float64)

Add adds v to the current value of g. If g is unset, sets g to v.

func (*Gauge) Set

func (g *Gauge) Set(v float64)

Set sets the value of the gauge. The gauge will continue to have this value until the next Set or Unset, or the end of the process.

func (*Gauge) Unset

func (g *Gauge) Unset()

Unset unsets the value of the gauge. If the Gauge remains unset, it will have no value for time buckets after this.

type GaugeDef

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

func NewGaugeDef

func NewGaugeDef(
	name string,
	description string,
	unit Unit,
) GaugeDef

type GaugeDef1

type GaugeDef1[V0 TagValue] struct {
	// contains filtered or unexported fields
}

GaugeDef1 is the definition of a gauge metric with 1 tag(s).

func NewGaugeDef1

func NewGaugeDef1[V0 TagValue](
	name string,
	description string,
	unit Unit,
	keys [1]string,

) GaugeDef1[V0]

NewGaugeDef1 defines a gauge metric with 1 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (GaugeDef1[V0]) Values

func (d GaugeDef1[V0]) Values(v0 V0) GaugeDef

Values returns a GaugeDef that has all of the given tag values bound. It can be passed to Metrics.Gauge() to produce a metric to log data to.

type GaugeDef2

type GaugeDef2[V0 TagValue, V1 TagValue] struct {
	// contains filtered or unexported fields
}

GaugeDef2 is the definition of a gauge metric with 2 tag(s).

func NewGaugeDef2

func NewGaugeDef2[V0 TagValue, V1 TagValue](
	name string,
	description string,
	unit Unit,
	keys [2]string,

) GaugeDef2[V0, V1]

NewGaugeDef2 defines a gauge metric with 2 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (GaugeDef2[V0, V1]) Prefix1

func (d GaugeDef2[V0, V1]) Prefix1(v0 V0) GaugeDef1[V1]

Prefix1 sets the value of the first 1 tags, returning a GaugeDef1 that can be used to set the rest.

func (GaugeDef2[V0, V1]) Values

func (d GaugeDef2[V0, V1]) Values(v0 V0, v1 V1) GaugeDef

Values returns a GaugeDef that has all of the given tag values bound. It can be passed to Metrics.Gauge() to produce a metric to log data to.

type GaugeDef3

type GaugeDef3[V0 TagValue, V1 TagValue, V2 TagValue] struct {
	// contains filtered or unexported fields
}

GaugeDef3 is the definition of a gauge metric with 3 tag(s).

func NewGaugeDef3

func NewGaugeDef3[V0 TagValue, V1 TagValue, V2 TagValue](
	name string,
	description string,
	unit Unit,
	keys [3]string,

) GaugeDef3[V0, V1, V2]

NewGaugeDef3 defines a gauge metric with 3 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (GaugeDef3[V0, V1, V2]) Prefix1

func (d GaugeDef3[V0, V1, V2]) Prefix1(v0 V0) GaugeDef2[V1, V2]

Prefix1 sets the value of the first 1 tags, returning a GaugeDef2 that can be used to set the rest.

func (GaugeDef3[V0, V1, V2]) Prefix2

func (d GaugeDef3[V0, V1, V2]) Prefix2(v0 V0, v1 V1) GaugeDef1[V2]

Prefix2 sets the value of the first 2 tags, returning a GaugeDef1 that can be used to set the rest.

func (GaugeDef3[V0, V1, V2]) Values

func (d GaugeDef3[V0, V1, V2]) Values(v0 V0, v1 V1, v2 V2) GaugeDef

Values returns a GaugeDef that has all of the given tag values bound. It can be passed to Metrics.Gauge() to produce a metric to log data to.

type GaugeDef4

type GaugeDef4[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue] struct {
	// contains filtered or unexported fields
}

GaugeDef4 is the definition of a gauge metric with 4 tag(s).

func NewGaugeDef4

func NewGaugeDef4[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue](
	name string,
	description string,
	unit Unit,
	keys [4]string,

) GaugeDef4[V0, V1, V2, V3]

NewGaugeDef4 defines a gauge metric with 4 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (GaugeDef4[V0, V1, V2, V3]) Prefix1

func (d GaugeDef4[V0, V1, V2, V3]) Prefix1(v0 V0) GaugeDef3[V1, V2, V3]

Prefix1 sets the value of the first 1 tags, returning a GaugeDef3 that can be used to set the rest.

func (GaugeDef4[V0, V1, V2, V3]) Prefix2

func (d GaugeDef4[V0, V1, V2, V3]) Prefix2(v0 V0, v1 V1) GaugeDef2[V2, V3]

Prefix2 sets the value of the first 2 tags, returning a GaugeDef2 that can be used to set the rest.

func (GaugeDef4[V0, V1, V2, V3]) Prefix3

func (d GaugeDef4[V0, V1, V2, V3]) Prefix3(v0 V0, v1 V1, v2 V2) GaugeDef1[V3]

Prefix3 sets the value of the first 3 tags, returning a GaugeDef1 that can be used to set the rest.

func (GaugeDef4[V0, V1, V2, V3]) Values

func (d GaugeDef4[V0, V1, V2, V3]) Values(v0 V0, v1 V1, v2 V2, v3 V3) GaugeDef

Values returns a GaugeDef that has all of the given tag values bound. It can be passed to Metrics.Gauge() to produce a metric to log data to.

type GaugeDef5

type GaugeDef5[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue, V4 TagValue] struct {
	// contains filtered or unexported fields
}

GaugeDef5 is the definition of a gauge metric with 5 tag(s).

func NewGaugeDef5

func NewGaugeDef5[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue, V4 TagValue](
	name string,
	description string,
	unit Unit,
	keys [5]string,

) GaugeDef5[V0, V1, V2, V3, V4]

NewGaugeDef5 defines a gauge metric with 5 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (GaugeDef5[V0, V1, V2, V3, V4]) Prefix1

func (d GaugeDef5[V0, V1, V2, V3, V4]) Prefix1(v0 V0) GaugeDef4[V1, V2, V3, V4]

Prefix1 sets the value of the first 1 tags, returning a GaugeDef4 that can be used to set the rest.

func (GaugeDef5[V0, V1, V2, V3, V4]) Prefix2

func (d GaugeDef5[V0, V1, V2, V3, V4]) Prefix2(v0 V0, v1 V1) GaugeDef3[V2, V3, V4]

Prefix2 sets the value of the first 2 tags, returning a GaugeDef3 that can be used to set the rest.

func (GaugeDef5[V0, V1, V2, V3, V4]) Prefix3

func (d GaugeDef5[V0, V1, V2, V3, V4]) Prefix3(v0 V0, v1 V1, v2 V2) GaugeDef2[V3, V4]

Prefix3 sets the value of the first 3 tags, returning a GaugeDef2 that can be used to set the rest.

func (GaugeDef5[V0, V1, V2, V3, V4]) Prefix4

func (d GaugeDef5[V0, V1, V2, V3, V4]) Prefix4(v0 V0, v1 V1, v2 V2, v3 V3) GaugeDef1[V4]

Prefix4 sets the value of the first 4 tags, returning a GaugeDef1 that can be used to set the rest.

func (GaugeDef5[V0, V1, V2, V3, V4]) Values

func (d GaugeDef5[V0, V1, V2, V3, V4]) Values(v0 V0, v1 V1, v2 V2, v3 V3, v4 V4) GaugeDef

Values returns a GaugeDef that has all of the given tag values bound. It can be passed to Metrics.Gauge() to produce a metric to log data to.

type GaugeGroup1

type GaugeGroup1[V0 TagValue] struct {
	// contains filtered or unexported fields
}

func NewGaugeGroup1

func NewGaugeGroup1[V0 TagValue](m *Metrics, d GaugeDef1[V0]) *GaugeGroup1[V0]

func (*GaugeGroup1[V0]) EmitAndUnset

func (g *GaugeGroup1[V0]) EmitAndUnset()

EmitAndUnset emits the gauges added using Set since the last EmitAndUnset, and unsets any tagsets that were not Set since the last EmitAndUnset.

func (*GaugeGroup1[V0]) Set

func (g *GaugeGroup1[V0]) Set(v0 V0, value float64)

type GaugeGroup2

type GaugeGroup2[V0 TagValue, V1 TagValue] struct {
	// contains filtered or unexported fields
}

func NewGaugeGroup2

func NewGaugeGroup2[V0 TagValue, V1 TagValue](m *Metrics, d *GaugeDef2[V0, V1]) *GaugeGroup2[V0, V1]

func (*GaugeGroup2[V0, V1]) EmitAndUnset

func (g *GaugeGroup2[V0, V1]) EmitAndUnset()

EmitAndUnset emits the gauges added using Set since the last EmitAndUnset, and unsets any tagsets that were not Set since the last EmitAndUnset.

func (*GaugeGroup2[V0, V1]) Set

func (g *GaugeGroup2[V0, V1]) Set(v0 V0, v1 V1, value float64)

type Metadata

type Metadata struct {
	MetricType  MetricType     `json:"metricType"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Unit        Unit           `json:"unit"`
	Keys        []string       `json:"keys"`
	ValueTypes  []reflect.Type `json:"-"`
	File        string         `json:"file"`
	Line        int            `json:"line"`
}

type MetricType

type MetricType string
const (
	CounterType      MetricType = "counter"
	GaugeType        MetricType = "gauge"
	DistributionType MetricType = "distribution"
	SetType          MetricType = "set"
)

type Metrics

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

func New

func New(p Publisher) *Metrics

func (*Metrics) Close

func (m *Metrics) Close()

Close frees resources associated with m. After Close, m should not be used.

func (*Metrics) Counter

func (m *Metrics) Counter(d CounterDef) *Counter

Counter returns the Counter for the given CounterDef. For the same CounterDef, including one produced from CounterDefY.Values() with the same values, this will return the same *Counter.

For metrics with tags (e.g. CounterDef2), the CounterDef can be made by calling Values(), for example:

// ---- metrics.go -----------------------------------------------------------------------------
rpcResponseDef = metrics.NewCounterDef2[string, string](
	"rpc_responses",
	"Counts responses to each RPC by method and status.",
	[...]string{"method", "status"},
	metrics.UnitResponse,
)

// ---- at the point of logging the metric -----------------------------------------------------
m.Counter(rpcResponseDef.Values(methodName, status)).Add(1)

Metrics.Counter is relatively expensive relative to Counter.Add, so very high-throughput logging should cache the result of this function:

// ---- at creation of RPC server --------------------------------------------------------------
// rpc_responses method:get status:ok
s.getOKCounter = m.Counter(rpcResponseDef.Values("get", "ok"))

// rpc_responses method:get status:error
s.getErrorCounter = m.Counter(rpcResponseDef.Values("get", "error"))

// ---- inside the Get() RPC handler -----------------------------------------------------------
if err == nil {
	s.getOKCounter.Add(1)
} else {
	s.getErrorCounter.Add(1)
}

func (*Metrics) Distribution

func (m *Metrics) Distribution(d DistributionDef) *Distribution

Distribution returns the Distribution for the given DistributionDef. For the same DistributionDef, including one produced from DistributionDefY.Values() with the same values, this will return the same *Distribution.

func (*Metrics) EveryFlush

func (m *Metrics) EveryFlush(f func()) func()

EveryFlush calls f once before each aggregate metric flush. This is useful for e.g. gauges that need to be periodically computed.

f happens on the same goroutine that flushes metrics, so it should not be too expensive or it can interfere with metrics being sent.

func (*Metrics) Flush

func (m *Metrics) Flush()

Flush immediately sends pending metric data to the Publisher given to m in New() and blocks until complete.

func (*Metrics) Gauge

func (m *Metrics) Gauge(d GaugeDef) *Gauge

Gauge returns the Gauge for the given GaugeDef. For the same GaugeDef, including one produced from GaugeDefY.Values() with the same values, this will return the same *Gauge.

func (*Metrics) Set

func (m *Metrics) Set(d SetDef) *Set

Set returns the Set for the given SetDef. For the same SetDef, including one produced from SetDefY.Values() with the same values, this will return the same *Set.

type Publisher

type Publisher interface {
	Gauge(name string, value float64, tags []string, rate float64) error
	Count(name string, value int64, tags []string, rate float64) error
	Distribution(name string, value float64, tags []string, rate float64) error
	Set(name string, value string, tags []string, rate float64) error
}

Publisher is the subset of github.com/DataDog/datadog-go/v5/statsd.ClientInterface used by this package.

Publisher should _not_ have client-side aggregation enabled because this package also does aggregation. It is enabled by default in datadog-go/v5, so should be disabled with statsd.WithoutClientSideAggregation().

type Set

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

Set measures the cardinality of values passed to Observe for each time bucket, that is, it estimates how many _unique_ values have been passed to it.

func (*Set) Observe

func (s *Set) Observe(value string)

type SetDef

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

func NewSetDef

func NewSetDef(
	name string,
	description string,
	unit Unit,
	sampleRate float64,
) SetDef

type SetDef1

type SetDef1[V0 TagValue] struct {
	// contains filtered or unexported fields
}

SetDef1 is the definition of a set metric with 1 tag(s).

func NewSetDef1

func NewSetDef1[V0 TagValue](
	name string,
	description string,
	unit Unit,
	keys [1]string,
	sampleRate float64,
) SetDef1[V0]

NewSetDef1 defines a set metric with 1 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (SetDef1[V0]) Values

func (d SetDef1[V0]) Values(v0 V0) SetDef

Values returns a SetDef that has all of the given tag values bound. It can be passed to Metrics.Set() to produce a metric to log data to.

type SetDef2

type SetDef2[V0 TagValue, V1 TagValue] struct {
	// contains filtered or unexported fields
}

SetDef2 is the definition of a set metric with 2 tag(s).

func NewSetDef2

func NewSetDef2[V0 TagValue, V1 TagValue](
	name string,
	description string,
	unit Unit,
	keys [2]string,
	sampleRate float64,
) SetDef2[V0, V1]

NewSetDef2 defines a set metric with 2 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (SetDef2[V0, V1]) Prefix1

func (d SetDef2[V0, V1]) Prefix1(v0 V0) SetDef1[V1]

Prefix1 sets the value of the first 1 tags, returning a SetDef1 that can be used to set the rest.

func (SetDef2[V0, V1]) Values

func (d SetDef2[V0, V1]) Values(v0 V0, v1 V1) SetDef

Values returns a SetDef that has all of the given tag values bound. It can be passed to Metrics.Set() to produce a metric to log data to.

type SetDef3

type SetDef3[V0 TagValue, V1 TagValue, V2 TagValue] struct {
	// contains filtered or unexported fields
}

SetDef3 is the definition of a set metric with 3 tag(s).

func NewSetDef3

func NewSetDef3[V0 TagValue, V1 TagValue, V2 TagValue](
	name string,
	description string,
	unit Unit,
	keys [3]string,
	sampleRate float64,
) SetDef3[V0, V1, V2]

NewSetDef3 defines a set metric with 3 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (SetDef3[V0, V1, V2]) Prefix1

func (d SetDef3[V0, V1, V2]) Prefix1(v0 V0) SetDef2[V1, V2]

Prefix1 sets the value of the first 1 tags, returning a SetDef2 that can be used to set the rest.

func (SetDef3[V0, V1, V2]) Prefix2

func (d SetDef3[V0, V1, V2]) Prefix2(v0 V0, v1 V1) SetDef1[V2]

Prefix2 sets the value of the first 2 tags, returning a SetDef1 that can be used to set the rest.

func (SetDef3[V0, V1, V2]) Values

func (d SetDef3[V0, V1, V2]) Values(v0 V0, v1 V1, v2 V2) SetDef

Values returns a SetDef that has all of the given tag values bound. It can be passed to Metrics.Set() to produce a metric to log data to.

type SetDef4

type SetDef4[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue] struct {
	// contains filtered or unexported fields
}

SetDef4 is the definition of a set metric with 4 tag(s).

func NewSetDef4

func NewSetDef4[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue](
	name string,
	description string,
	unit Unit,
	keys [4]string,
	sampleRate float64,
) SetDef4[V0, V1, V2, V3]

NewSetDef4 defines a set metric with 4 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (SetDef4[V0, V1, V2, V3]) Prefix1

func (d SetDef4[V0, V1, V2, V3]) Prefix1(v0 V0) SetDef3[V1, V2, V3]

Prefix1 sets the value of the first 1 tags, returning a SetDef3 that can be used to set the rest.

func (SetDef4[V0, V1, V2, V3]) Prefix2

func (d SetDef4[V0, V1, V2, V3]) Prefix2(v0 V0, v1 V1) SetDef2[V2, V3]

Prefix2 sets the value of the first 2 tags, returning a SetDef2 that can be used to set the rest.

func (SetDef4[V0, V1, V2, V3]) Prefix3

func (d SetDef4[V0, V1, V2, V3]) Prefix3(v0 V0, v1 V1, v2 V2) SetDef1[V3]

Prefix3 sets the value of the first 3 tags, returning a SetDef1 that can be used to set the rest.

func (SetDef4[V0, V1, V2, V3]) Values

func (d SetDef4[V0, V1, V2, V3]) Values(v0 V0, v1 V1, v2 V2, v3 V3) SetDef

Values returns a SetDef that has all of the given tag values bound. It can be passed to Metrics.Set() to produce a metric to log data to.

type SetDef5

type SetDef5[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue, V4 TagValue] struct {
	// contains filtered or unexported fields
}

SetDef5 is the definition of a set metric with 5 tag(s).

func NewSetDef5

func NewSetDef5[V0 TagValue, V1 TagValue, V2 TagValue, V3 TagValue, V4 TagValue](
	name string,
	description string,
	unit Unit,
	keys [5]string,
	sampleRate float64,
) SetDef5[V0, V1, V2, V3, V4]

NewSetDef5 defines a set metric with 5 tag(s).

It must be called from a top-level var block in a file called metrics.go, otherwise it will panic (if main() has not yet started) or return an inert def that will not produce any data.

func (SetDef5[V0, V1, V2, V3, V4]) Prefix1

func (d SetDef5[V0, V1, V2, V3, V4]) Prefix1(v0 V0) SetDef4[V1, V2, V3, V4]

Prefix1 sets the value of the first 1 tags, returning a SetDef4 that can be used to set the rest.

func (SetDef5[V0, V1, V2, V3, V4]) Prefix2

func (d SetDef5[V0, V1, V2, V3, V4]) Prefix2(v0 V0, v1 V1) SetDef3[V2, V3, V4]

Prefix2 sets the value of the first 2 tags, returning a SetDef3 that can be used to set the rest.

func (SetDef5[V0, V1, V2, V3, V4]) Prefix3

func (d SetDef5[V0, V1, V2, V3, V4]) Prefix3(v0 V0, v1 V1, v2 V2) SetDef2[V3, V4]

Prefix3 sets the value of the first 3 tags, returning a SetDef2 that can be used to set the rest.

func (SetDef5[V0, V1, V2, V3, V4]) Prefix4

func (d SetDef5[V0, V1, V2, V3, V4]) Prefix4(v0 V0, v1 V1, v2 V2, v3 V3) SetDef1[V4]

Prefix4 sets the value of the first 4 tags, returning a SetDef1 that can be used to set the rest.

func (SetDef5[V0, V1, V2, V3, V4]) Values

func (d SetDef5[V0, V1, V2, V3, V4]) Values(v0 V0, v1 V1, v2 V2, v3 V3, v4 V4) SetDef

Values returns a SetDef that has all of the given tag values bound. It can be passed to Metrics.Set() to produce a metric to log data to.

type TagValue

type TagValue any

TagValue is the value of a key:value pair in a metric tag. They are formatted the same as fmt.Sprint unless the type implements TagValuer, in which case MetricTagValue() is used instead.

TagValues that produce the same string are considered the same.

type TagValuer

type TagValuer interface {
	MetricTagValue() string
}

See the comment on type TagValue.

type Unit

type Unit string
const (
	NoUnits Unit = ""

	// BYTES
	UnitBit      Unit = "bit"
	UnitByte     Unit = "byte"
	UnitKibibyte Unit = "kibibyte"
	UnitMebibyte Unit = "mebibyte"
	UnitGibibyte Unit = "gibibyte"
	UnitTebibyte Unit = "tebibyte"
	UnitPebibyte Unit = "pebibyte"
	UnitExbibyte Unit = "exbibyte"

	// TIME
	UnitNanosecond  Unit = "nanosecond"
	UnitMicrosecond Unit = "microsecond"
	UnitMillisecond Unit = "millisecond"
	UnitSecond      Unit = "second"
	UnitMinute      Unit = "minute"
	UnitHour        Unit = "hour"
	UnitDay         Unit = "day"
	UnitWeek        Unit = "week"

	// PERCENTAGE
	UnitPercentNano Unit = "percent_nano"
	UnitPercent     Unit = "percent"
	UnitApdex       Unit = "apdex"
	UnitFraction    Unit = "fraction"

	// NETWORK
	UnitConnection Unit = "connection"
	UnitRequest    Unit = "request"
	UnitPacket     Unit = "packet"
	UnitSegment    Unit = "segment"
	UnitResponse   Unit = "response"
	UnitMessage    Unit = "message"
	UnitPayload    Unit = "payload"
	UnitTimeout    Unit = "timeout"
	UnitDatagram   Unit = "datagram"
	UnitRoute      Unit = "route"
	UnitSession    Unit = "session"
	UnitHop        Unit = "hop"

	// SYSTEM
	UnitProcess  Unit = "process"
	UnitThread   Unit = "thread"
	UnitHost     Unit = "host"
	UnitNode     Unit = "node"
	UnitFault    Unit = "fault"
	UnitService  Unit = "service"
	UnitInstance Unit = "instance"
	UnitCPU      Unit = "cpu"

	// DISK
	UnitFile   Unit = "file"
	UnitInode  Unit = "inode"
	UnitSector Unit = "sector"
	UnitBlock  Unit = "block"

	// GENERAL
	UnitBuffer            Unit = "buffer"
	UnitError             Unit = "error"
	UnitRead              Unit = "read"
	UnitWrite             Unit = "write"
	UnitOccurrence        Unit = "occurrence"
	UnitEvent             Unit = "event"
	UnitTime              Unit = "time"
	UnitUnit              Unit = "unit"
	UnitOperation         Unit = "operation"
	UnitItem              Unit = "item"
	UnitTask              Unit = "task"
	UnitWorker            Unit = "worker"
	UnitResource          Unit = "resource"
	UnitGarbageCollection Unit = "garbage collection"
	UnitEmail             Unit = "email"
	UnitSample            Unit = "sample"
	UnitStage             Unit = "stage"
	UnitMonitor           Unit = "monitor"
	UnitLocation          Unit = "location"
	UnitCheck             Unit = "check"
	UnitAttempt           Unit = "attempt"
	UnitDevice            Unit = "device"
	UnitUpdate            Unit = "update"
	UnitMethod            Unit = "method"
	UnitJob               Unit = "job"
	UnitContainer         Unit = "container"
	UnitExecution         Unit = "execution"
	UnitThrottle          Unit = "throttle"
	UnitInvocation        Unit = "invocation"
	UnitUser              Unit = "user"
	UnitSuccess           Unit = "success"
	UnitBuild             Unit = "build"
	UnitPrediction        Unit = "prediction"
	UnitException         Unit = "exception"

	// DB
	UnitTable       Unit = "table"
	UnitIndex       Unit = "index"
	UnitLock        Unit = "lock"
	UnitTransaction Unit = "transaction"
	UnitQuery       Unit = "query"
	UnitRow         Unit = "row"
	UnitKey         Unit = "key"
	UnitCommand     Unit = "command"
	UnitOffset      Unit = "offset"
	UnitRecord      Unit = "record"
	UnitObject      Unit = "object"
	UnitCursor      Unit = "cursor"
	UnitAssertion   Unit = "assertion"
	UnitScan        Unit = "scan"
	UnitDocument    Unit = "document"
	UnitShard       Unit = "shard"
	UnitFlush       Unit = "flush"
	UnitMerge       Unit = "merge"
	UnitRefresh     Unit = "refresh"
	UnitFetch       Unit = "fetch"
	UnitColumn      Unit = "column"
	UnitCommit      Unit = "commit"
	UnitWait        Unit = "wait"
	UnitTicket      Unit = "ticket"
	UnitQuestion    Unit = "question"

	// CACHE
	UnitHit      Unit = "hit"
	UnitMiss     Unit = "miss"
	UnitEviction Unit = "eviction"
	UnitGet      Unit = "get"
	UnitSet      Unit = "set"

	// MONEY
	UnitDollar      Unit = "dollar"
	UnitCent        Unit = "cent"
	UnitMicrodollar Unit = "microdollar"
	UnitEuro        Unit = "euro"

	// MEMORY
	UnitPage  Unit = "page"
	UnitSplit Unit = "split"

	// FREQUENCY
	UnitHertz     Unit = "hertz"
	UnitKilohertz Unit = "kilohertz"
	UnitMegahertz Unit = "megahertz"
	UnitGigahertz Unit = "gigahertz"

	// LOGGING
	UnitEntry Unit = "entry"

	// TEMPERATURE
	UnitDecidegreeCelsius Unit = "decidegree celsius"
	UnitDegreeCelsius     Unit = "degree celsius"
	UnitDegreeFahrenheit  Unit = "degree fahrenheit"

	// CPU
	UnitNanocore  Unit = "nanocore"
	UnitMicrocore Unit = "microcore"
	UnitMillicore Unit = "millicore"
	UnitCore      Unit = "core"
	UnitKilocore  Unit = "kilocore"
	UnitMegacore  Unit = "megacore"
	UnitGigacore  Unit = "gigacore"
	UnitTeracore  Unit = "teracore"
	UnitPetacore  Unit = "petacore"
	UnitExacore   Unit = "exacore"

	// POWER
	UnitNanowatt  Unit = "nanowatt"
	UnitMicrowatt Unit = "microwatt"
	UnitMilliwatt Unit = "milliwatt"
	UnitDeciwatt  Unit = "deciwatt"
	UnitWatt      Unit = "watt"
	UnitKilowatt  Unit = "kilowatt"
	UnitMegawatt  Unit = "megawatt"
	UnitGigawatt  Unit = "gigawatt"
	UnitTerrawatt Unit = "terrawatt"

	// CURRENT
	UnitMilliampere Unit = "milliampere"
	UnitAmpere      Unit = "ampere"

	// POTENTIAL
	UnitMillivolt Unit = "millivolt"
	UnitVolt      Unit = "volt"

	// APM
	UnitSpan Unit = "span"

	// SYNTHETICS
	UnitRun Unit = "run"
)

Copied from https://docs.datadoghq.com/metrics/units/#unit-list

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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