Additional Metrics - docker/go-metrics

Additional Metrics in github.com/docker/go-metrics:

The github.com/docker/go-metrics library provides several options for additional metrics beyond the basic ones. Here are some of the possible options with examples:

  1. Histogram Metric: Histogram is a more complex metric type that can be used for any calculated value which is counted based on bucket values. A common example would be the time it takes to reply to a request, called latency. Here’s an example of creating a histogram metric:
h := metrics.NewHistogram(
metrics.NewOptions(
metrics.WithName("request_latency_seconds"),
metrics.WithStdevBucketBoundaries([]float64{.005, .01, .025, .05, .1, .25, .5, .75, 1, 2.5, 5, 10}),
),
)
h.Observe(time.Since(start).Seconds())

PromQL functions like max_over_time, min_over_time and avg_over_time can be used on gauge metrics.

  1. Disabled Metrics: The library also provides a way to track the count of disabled metrics. Here’s an example of creating a disabled metric:
c := metrics.NewDisabledCounter(
metrics.NewOptions(
metrics.WithName("disabled_metric_total"),
),
)
c.Inc(1)
  1. Field Metrics: Field metrics can be used to track the response latency distribution in seconds for each field validation value and whether field validation is enabled or not. Here’s an example of creating a field metric:
f := metrics.NewSummary(
metrics.NewOptions(
metrics.WithName("field_validation_request_duration_seconds"),
),
)
f.Observe(time.Since(start).Seconds())
  1. Go Metrics: The library also provides several pre-defined metrics for the Go runtime, such as the count of calls made from Go to C by the current process, and the estimated total CPU time goroutines spent performing GC tasks to assist the GC and prevent it from falling behind the application. Here’s an example of creating a Go metric:
g := metrics.NewGauge(
metrics.NewOptions(
metrics.WithName("go_cgo_go_to_c_calls_calls_total"),
),
)
g.Set(123)

For more information, you can refer to the following links: