metrics

package
v2.19.2 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 11 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(name string, value int64, options ...Option)

Count tracks how many times something happened per second.

func Decr

func Decr(name string, options ...Option)

Decr is just Count of -1

func Distribution

func Distribution(name string, value float64, options ...Option)

Distribution tracks the statistical distribution of a set of values across your infrastructure.

func Flush

func Flush() error

Flush forces a flush of all the queued dogstatsd payloads.

func Gauge

func Gauge(name string, value float64, options ...Option)

Gauge measures the value of a metric at a particular time.

func GlobalSetup

func GlobalSetup(options ...Option) error

GlobalSetup configures the Dogstatsd Client. GlobalSetup is intended to be called from coopdatadog.Start(), but can be called directly.

func Histogram

func Histogram(name string, value float64, options ...Option)

Histogram tracks the statistical distribution of a set of values on each host.

func Incr

func Incr(name string, options ...Option)

Incr is just Count of 1

func Set

func Set(name string, value string, options ...Option)

Set counts the number of unique elements in a group.

func SimpleEvent

func SimpleEvent(title, text string)

SimpleEvent sends an event with the provided title and text.

func TimeInMilliseconds

func TimeInMilliseconds(name string, value float64, options ...Option)

TimeInMilliseconds sends timing information in milliseconds.

func Timing

func Timing(name string, value time.Duration, options ...Option)

Timing sends timing information, it is an alias for TimeInMilliseconds

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

func WithSampleRate(rate float64) Option

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)

func WithTag added in v2.17.0

func WithTag(k, v string) Option

WithTag sets a tag that will be sent with a specific metric. Parameters:

  • k: The tag key
  • v: The tag value

Jump to

Keyboard shortcuts

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