Metric Declaration and Management - docker/go-metrics

The github.com/docker/go-metrics library is used for metric declaration and management in Go applications. It is based on the prometheus client libraries and provides support for various types of metrics.

The following metric types are supported:

  • Labeled Counter Metric: A counter metric that can be incremented or reset to a specific value. It is useful for tracking the total number of events or occurrences.

Example:

import "github.com/docker/go-metrics"

// ...

counter := metrics.NewCounter("my_counter", "A labeled counter metric")
counter.Add(42, metrics.Tag{"label1": "value1", "label2": "value2"})
  • Labeled Gauge Metric: A gauge metric that can be set to any arbitrary value. It is useful for tracking the current state or value of a particular metric.

Example:

import "github.com/docker/go-metrics"

// ...

gauge := metrics.NewGauge("my_gauge", "A labeled gauge metric")
gauge.Set(42, metrics.Tag{"label1": "value1", "label2": "value2"})
  • Labeled Timer Metric: A timer metric that can be used to track the duration of events or operations. It is useful for tracking latency or response times.

Example:

import "github.com/docker/go-metrics"

// ...

timer := metrics.NewTimer("my_timer", "A labeled timer metric")
timer.Record(time.Duration(42), metrics.Tag{"label1": "value1", "label2": "value2"})

The github.com/docker/go-metrics library also supports non-global registries, functions for pushing metrics to Prometheus PushGateways, and bridging Prometheus and Graphite.

For more information, see the following resources:

Note: The github.com/docker/go-metrics library is no longer actively maintained and has been replaced by the OpenTelemetry Go Metrics SDK. However, it can still be used for metric declaration and management in Go applications.