kit: github.com/go-kit/kit/metrics/provider Index | Files

package provider

import "github.com/go-kit/kit/metrics/provider"

Package provider provides a factory-like abstraction for metrics backends. This package is provided specifically for the needs of the NY Times framework Gizmo. Most normal Go kit users shouldn't need to use it.

Normally, if your microservice needs to support different metrics backends, you can simply do different construction based on a flag. For example,

var latency metrics.Histogram
var requests metrics.Counter
switch *metricsBackend {
case "prometheus":
    latency = prometheus.NewSummaryVec(...)
    requests = prometheus.NewCounterVec(...)
case "statsd":
    s := statsd.New(...)
    t := time.NewTicker(5*time.Second)
    go s.SendLoop(t.C, "tcp", "statsd.local:8125")
    latency = s.NewHistogram(...)
    requests = s.NewCounter(...)
default:
    log.Fatal("unsupported metrics backend %q", *metricsBackend)
}

Index

Package Files

discard.go dogstatsd.go expvar.go graphite.go influx.go prometheus.go provider.go statsd.go

type Provider Uses

type Provider interface {
    NewCounter(name string) metrics.Counter
    NewGauge(name string) metrics.Gauge
    NewHistogram(name string, buckets int) metrics.Histogram
    Stop()
}

Provider abstracts over constructors and lifecycle management functions for each supported metrics backend. It should only be used by those who need to swap out implementations dynamically.

This is primarily useful for intermediating frameworks, and is likely unnecessary for most Go kit services. See the package-level doc comment for more typical usage instructions.

func NewDiscardProvider Uses

func NewDiscardProvider() Provider

NewDiscardProvider returns a provider that produces no-op metrics via the discarding backend.

func NewDogstatsdProvider Uses

func NewDogstatsdProvider(d *dogstatsd.Dogstatsd, stop func()) Provider

NewDogstatsdProvider wraps the given Dogstatsd object and stop func and returns a Provider that produces Dogstatsd metrics. A typical stop function would be ticker.Stop from the ticker passed to the SendLoop helper method.

func NewExpvarProvider Uses

func NewExpvarProvider() Provider

NewExpvarProvider returns a Provider that produces expvar metrics.

func NewGraphiteProvider Uses

func NewGraphiteProvider(g *graphite.Graphite, stop func()) Provider

NewGraphiteProvider wraps the given Graphite object and stop func and returns a Provider that produces Graphite metrics. A typical stop function would be ticker.Stop from the ticker passed to the SendLoop helper method.

func NewInfluxProvider Uses

func NewInfluxProvider(in *influx.Influx, stop func()) Provider

NewInfluxProvider takes the given Influx object and stop func, and returns a Provider that produces Influx metrics.

func NewPrometheusProvider Uses

func NewPrometheusProvider(namespace, subsystem string) Provider

NewPrometheusProvider returns a Provider that produces Prometheus metrics. Namespace and subsystem are applied to all produced metrics.

func NewStatsdProvider Uses

func NewStatsdProvider(s *statsd.Statsd, stop func()) Provider

NewStatsdProvider wraps the given Statsd object and stop func and returns a Provider that produces Statsd metrics. A typical stop function would be ticker.Stop from the ticker passed to the SendLoop helper method.

Package provider imports 9 packages (graph) and is imported by 2 packages. Updated 2017-01-17. Refresh now. Tools for package owners.