package
0.0.0-20171009231159-a11eda293c5f
Repository: https://github.com/codelingo/kit.git
Documentation: pkg.go.dev
# README
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 "github.com/go-kit/kit/metrics/expvar"
func main() {
myCount := expvar.NewCounter("my_count")
myCount.Add(1)
}
A histogram for request duration, exported via a Prometheus summary with dynamically-computed quantiles.
import (
stdprometheus "github.com/prometheus/client_golang/prometheus"
"github.com/go-kit/kit/metrics"
"github.com/go-kit/kit/metrics/prometheus"
)
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 (
"net"
"os"
"runtime"
"time"
"github.com/go-kit/kit/metrics/statsd"
)
func main() {
statsdWriter, err := net.Dial("udp", "127.0.0.1:8126")
if err != nil {
panic(err)
}
reportInterval := 5 * time.Second
goroutines := statsd.NewGauge(statsdWriter, "total_goroutines", reportInterval)
for range time.Tick(reportInterval) {
goroutines.Set(float64(runtime.NumGoroutine()))
}
}
# Packages
Package circonus provides a Circonus backend for package metrics.
Package discard implements a backend for package metrics that succeeds without doing anything.
Package dogstatsd implements a DogStatsD backend for package metrics.
Package expvar implements an expvar backend for package metrics.
Package graphite implements a Graphite backend for package metrics.
Package influxdb implements a InfluxDB backend for package metrics.
Package prometheus implements a Prometheus backend for package metrics.
No description provided by the author
Package statsd implements a statsd backend for package metrics.
Package teststat contains helper functions for statistical testing of metrics implementations.
# Functions
NewMultiCounter returns a wrapper around multiple Counters.
NewMultiGauge returns a wrapper around multiple Gauges.
NewMultiHistogram returns a wrapper around multiple Histograms.
NewScaledHistogram returns a Histogram whose observed values are downscaled (divided) by scale.
NewTimeHistogram returns a TimeHistogram wrapper around the passed Histogram, in units of unit.
PrintDistribution writes a human-readable graph of the distribution to the passed writer.
# Interfaces
Counter is a monotonically-increasing, unsigned, 64-bit integer used to capture the number of times an event has occurred.
Gauge captures instantaneous measurements of something using signed, 64-bit floats.
Histogram tracks the distribution of a stream of values (e.g.
TimeHistogram is a convenience wrapper for a Histogram of time.Durations.