Documentation
¶
Overview ¶
Package metrics implements custom metrics with Dogstatsd
Example ¶
package main import ( "context" coopdatadog "github.com/coopnorge/go-datadog-lib/v2" "github.com/coopnorge/go-datadog-lib/v2/metrics" ) func main() { err := run() if err != nil { panic(err) } } func run() error { stop, err := coopdatadog.Start(context.Background()) if err != nil { return err } defer func() { err := stop() if err != nil { panic(err) } }() metrics.Incr("my-metric") metrics.Count("metric.with.options", 1, metrics.WithTag("tag1", "value1")) metrics.Gauge("gauge.with.options", 42.0, metrics.WithTag("tag1", "test1"), metrics.WithSampleRate(0.5)) return nil }
Index ¶
- func Count(name string, value int64, options ...Option)
- func Decr(name string, options ...Option)
- func Distribution(name string, value float64, options ...Option)
- func Flush() error
- func Gauge(name string, value float64, options ...Option)
- func GlobalSetup(options ...Option) error
- func Histogram(name string, value float64, options ...Option)
- func Incr(name string, options ...Option)
- func Set(name string, value string, options ...Option)
- func SimpleEvent(title, text string)
- func TimeInMilliseconds(name string, value float64, options ...Option)
- func Timing(name string, value time.Duration, options ...Option)
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Distribution ¶
Distribution tracks the statistical distribution of a set of values across your infrastructure.
func GlobalSetup ¶
GlobalSetup configures the Dogstatsd Client. GlobalSetup is intended to be called from coopdatadog.Start(), but can be called directly.
func SimpleEvent ¶
func SimpleEvent(title, text string)
SimpleEvent sends an event with the provided title and text.
func TimeInMilliseconds ¶
TimeInMilliseconds sends timing information in milliseconds.
Types ¶
type Option ¶
type Option func(*options) error
Option is used to configure the behaviour of the metrics integration.
func WithErrorHandler ¶
func WithErrorHandler(handler ddErrors.ErrorHandler) Option
WithErrorHandler allows for setting a custom ErrorHandler to be called on function that may error but does not return an error
func WithSampleRate ¶ added in v2.17.0
WithSampleRate sets the sample rate for metrics collection. The sample rate controls what percentage of metrics are actually sent to the backend Parameters:
- rate: A float between 0 and 1 representing the sampling percentage:
- 0: No metrics will be sent (0%)
- 1: All metrics will be sent (100%)
- between 0 and 1 means that % of metrics will be sent (0.25 = 25%)
Returns an error if the rate is invalid (negative)