The Go metrics library for Docker projects provides various options for namespace and subsystem creation. This document outlines the possible options with examples using the “github.com/docker/go-metrics” module.
Namespace and Subsystem Creation
In the Go metrics library, the Registry
type is used to manage and expose metrics. When creating a new metric, you can specify a namespace and subsystem for better organization and grouping of related metrics.
Quoting the Go metrics documentation:
A
Registry
is a container forMetric
s. It is safe for concurrent use by multiple goroutines.
Option 1: No Namespace or Subsystem
If no namespace or subsystem is specified, the metric will be created at the root level.
import "github.com/docker/go-metrics"
// Create a gauge metric at the root level
g := metrics.NewGauge()
Option 2: Namespace Only
You can specify a namespace for the metric to be organized under.
import "github.com/docker/go-metrics"
// Create a gauge metric under the "example" namespace
g := metrics.NewGauge("example", nil)
Option 3: Namespace and Subsystem
You can specify both a namespace and a subsystem for the metric to be organized under.
import "github.com/docker/go-metrics"
// Create a gauge metric under the "example" namespace and "subsystem1" subsystem
g := metrics.NewGauge("example", "subsystem1", nil)
Additional Resources
- Agents - Enable Telemetry Metrics | Consul | HashiCorp Developer
- Registry | OpenTelemetry
- Instrumenting a Go application | Prometheus
- How to Use Go Modules | DigitalOcean
- Metrics Semantic Conventions | OpenTelemetry
- Semantic Conventions for Runtime Environment | OpenTelemetry
- Manual instrumentation of Go applications with OpenTelemetry Metrics SDK | Opentelemetry documentation
- Sensu | Monitoring as Code (The Sensu Blog)