Codebase list golang-github-go-kit-kit / 203e4782-15ed-484f-9517-a1c12654c5bc/v0.1.0 metrics

Tree @203e4782-15ed-484f-9517-a1c12654c5bc/v0.1.0 (Download .tar.gz)

# package metrics

`package metrics` provides a set of uniform interfaces for service instrumentation.
It has **[counters][]**, **[gauges][]**, and **[histograms][]**,
 and provides adapters to popular metrics packages, like **[expvar][]**, **[statsd][]**, and **[Prometheus][]**.


## Rationale

Code instrumentation is absolutely essential to achieve [observability][] into a distributed system.
Metrics and instrumentation tools have coalesced around a few well-defined idioms.
`package metrics` provides a common, minimal interface those idioms for service authors. 


## Usage

A simple counter, exported via expvar.

import ""

func main() {
	myCount := expvar.NewCounter("my_count")

A histogram for request duration, exported via a Prometheus summary with
dynamically-computed quantiles.

import (
	stdprometheus ""


var requestDuration = prometheus.NewSummary(stdprometheus.SummaryOpts{
	Namespace: "myservice",
	Subsystem: "api",
	Name:      "request_duration_nanoseconds_count",
	Help:      "Total time spent serving requests.",
}, []string{})

func handleRequest() {
	defer func(begin time.Time) { requestDuration.Observe(time.Since(begin)) }(time.Now())
	// handle request

A gauge for the number of goroutines currently running, exported via statsd.

import (


func main() {
	statsdWriter, err := net.Dial("udp", "")
	if err != nil {

	reportInterval := 5 * time.Second
	goroutines := statsd.NewGauge(statsdWriter, "total_goroutines", reportInterval)
	for range time.Tick(reportInterval) {

History of metrics @203e4782-15ed-484f-9517-a1c12654c5bc/v0.1.0