metrics

package
v0.0.0-...-2b7dcb4 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: BSD-2-Clause Imports: 6 Imported by: 0

README

Description

Reports custom metrics to DataDog.

Packages

Usage

metrics.SetEmpireDefaultTags() // sets empire.app.name, empire.app.process, empire.app.release and
                               // container_id tags on every metric.

metrics.Reporter, _ = NewDataDogMetricsReporter("statsd:2026")
defer metrics.Close()
...
metrics.Count("mycount", 1, map[string]string{"feature_version":"v1"}, 1.0)

See metrics.go for more examples.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RuntimeMetricsSamplingInterval time.Duration = 30 * time.Second

sets how often the metrics Runtime will sample and emit stats.

Functions

func Close

func Close() error

Close closes the backend connection cleanly

func Count

func Count(name string, value int64, tags map[string]string, rate float64) error

func Distribution

func Distribution(name string, value float64, tags map[string]string, rate float64) error

func Gauge

func Gauge(name string, value float64, tags map[string]string, rate float64) error

func Histogram

func Histogram(name string, value float64, tags map[string]string, rate float64) error

func ReportRuntimeMetrics

func ReportRuntimeMetrics()

Samples and reports current runtime status once.

func ResponseTime

func ResponseTime() *timer

ResponseTime is a shorthand for reporting web response time.

Usage:

t := metrics.ResponseTime()
defer t.Done()
...
t.SetTags(map[string]string{"route":"GET /foo/bar"})

func Runtime

func Runtime()

Runtime enters into a loop, sampling and outputing the runtime stats periodically. Usage:

func main() {
  ...
  go metrics.Runtime()
  ...
}

func Set

func Set(name string, value string, tags map[string]string, rate float64) error

func SetEmpireDefaultTags

func SetEmpireDefaultTags()

SetEmpireDefaultTags sets default tags reflecting the empire environment to each metric

func Time

func Time(name string, tags map[string]string, rate float64) *timer

Time is a shorthand for TimeInMilliseconds for easy code block instrumentation

Usage:

t := metrics.Time("foo.bar", map[string]string{"baz":"qux"}, 1.0)
defer t.Done()
...
t.SetTags(map[string]string{"foo":"bar"}) // totally optional

func TimeInMilliseconds

func TimeInMilliseconds(name string, value float64, tags map[string]string, rate float64) error

Types

type DataDogMetricsReporter

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

func NewDataDogMetricsReporter

func NewDataDogMetricsReporter(addr string) (*DataDogMetricsReporter, error)

func (*DataDogMetricsReporter) Close

func (c *DataDogMetricsReporter) Close() error

func (*DataDogMetricsReporter) Count

func (c *DataDogMetricsReporter) Count(name string, value int64, tags map[string]string, rate float64) error

func (*DataDogMetricsReporter) Distribution

func (c *DataDogMetricsReporter) Distribution(name string, value float64, tags map[string]string, rate float64) error

func (*DataDogMetricsReporter) Gauge

func (c *DataDogMetricsReporter) Gauge(name string, value float64, tags map[string]string, rate float64) error

func (*DataDogMetricsReporter) Histogram

func (c *DataDogMetricsReporter) Histogram(name string, value float64, tags map[string]string, rate float64) error

func (*DataDogMetricsReporter) Set

func (c *DataDogMetricsReporter) Set(name string, value string, tags map[string]string, rate float64) error

func (*DataDogMetricsReporter) TimeInMilliseconds

func (c *DataDogMetricsReporter) TimeInMilliseconds(name string, value float64, tags map[string]string, rate float64) error

type MetricsReporter

type MetricsReporter interface {
	Count(name string, value int64, tags map[string]string, rate float64) error
	Gauge(name string, value float64, tags map[string]string, rate float64) error
	Histogram(name string, value float64, tags map[string]string, rate float64) error
	Distribution(name string, value float64, tags map[string]string, rate float64) error
	Set(name string, value string, tags map[string]string, rate float64) error
	TimeInMilliseconds(name string, value float64, tags map[string]string, rate float64) error
	Close() error
}
var Reporter MetricsReporter

Usage:

metrics.SetEmpireDefaultTags()
metrics.Reporter, _ = NewDataDogMetricsReporter("statsd:2026")
defer metrics.Close()
...
metrics.Count("mycount", 1, map[string]string{"feature_version":"v1"}, 1.0)

type NoopMetricsReporter

type NoopMetricsReporter struct{}

func (*NoopMetricsReporter) Close

func (c *NoopMetricsReporter) Close() error

func (*NoopMetricsReporter) Count

func (c *NoopMetricsReporter) Count(name string, value int64, tags map[string]string, rate float64) error

func (*NoopMetricsReporter) Distribution

func (c *NoopMetricsReporter) Distribution(name string, value float64, tags map[string]string, rate float64) error

func (*NoopMetricsReporter) Gauge

func (c *NoopMetricsReporter) Gauge(name string, value float64, tags map[string]string, rate float64) error

func (*NoopMetricsReporter) Histogram

func (c *NoopMetricsReporter) Histogram(name string, value float64, tags map[string]string, rate float64) error

func (*NoopMetricsReporter) Set

func (c *NoopMetricsReporter) Set(name string, value string, tags map[string]string, rate float64) error

func (*NoopMetricsReporter) TimeInMilliseconds

func (c *NoopMetricsReporter) TimeInMilliseconds(name string, value float64, tags map[string]string, rate float64) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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