...

Package metrics

import "github.com/docker/go-metrics"
Overview
Index

Overview ▾

Index ▾

Constants
func Deregister(n *Namespace)
func Handler() http.Handler
func InstrumentHandler(metrics []*HTTPMetric, handler http.Handler) http.HandlerFunc
func InstrumentHandlerFunc(metrics []*HTTPMetric, handlerFunc http.HandlerFunc) http.HandlerFunc
func Register(n *Namespace)
func StartTimer(timer Timer) (done func())
type Counter
type Gauge
type HTTPHandlerOpts
type HTTPMetric
type LabeledCounter
type LabeledGauge
type LabeledTimer
type Labels
type Namespace
    func NewNamespace(name, subsystem string, labels Labels) *Namespace
    func (n *Namespace) Add(collector prometheus.Collector)
    func (n *Namespace) Collect(ch chan<- prometheus.Metric)
    func (n *Namespace) Describe(ch chan<- *prometheus.Desc)
    func (n *Namespace) NewCounter(name, help string) Counter
    func (n *Namespace) NewDefaultHttpMetrics(handlerName string) []*HTTPMetric
    func (n *Namespace) NewDesc(name, help string, unit Unit, labels ...string) *prometheus.Desc
    func (n *Namespace) NewGauge(name, help string, unit Unit) Gauge
    func (n *Namespace) NewHttpMetrics(handlerName string, durationBuckets, requestSizeBuckets, responseSizeBuckets []float64) []*HTTPMetric
    func (n *Namespace) NewHttpMetricsWithOpts(handlerName string, opts HTTPHandlerOpts) []*HTTPMetric
    func (n *Namespace) NewInFlightGaugeMetric(handlerName string) *HTTPMetric
    func (n *Namespace) NewLabeledCounter(name, help string, labels ...string) LabeledCounter
    func (n *Namespace) NewLabeledGauge(name, help string, unit Unit, labels ...string) LabeledGauge
    func (n *Namespace) NewLabeledTimer(name, help string, labels ...string) LabeledTimer
    func (n *Namespace) NewRequestDurationMetric(handlerName string, buckets []float64) *HTTPMetric
    func (n *Namespace) NewRequestSizeMetric(handlerName string, buckets []float64) *HTTPMetric
    func (n *Namespace) NewRequestTotalMetric(handlerName string) *HTTPMetric
    func (n *Namespace) NewResponseSizeMetric(handlerName string, buckets []float64) *HTTPMetric
    func (n *Namespace) NewTimer(name, help string) Timer
    func (n *Namespace) WithConstLabels(labels Labels) *Namespace
type Timer
type Unit

Package files

counter.go docs.go gauge.go handler.go helpers.go namespace.go register.go timer.go unit.go

Constants

const (
    InstrumentHandlerResponseSize = iota
    InstrumentHandlerRequestSize
    InstrumentHandlerDuration
    InstrumentHandlerCounter
    InstrumentHandlerInFlight
)

func Deregister

func Deregister(n *Namespace)

Deregister removes all the metrics in the provided namespace from the global metrics registry

func Handler

func Handler() http.Handler

Handler returns the global http.Handler that provides the prometheus metrics format on GET requests. This handler is no longer instrumented.

func InstrumentHandler

func InstrumentHandler(metrics []*HTTPMetric, handler http.Handler) http.HandlerFunc

func InstrumentHandlerFunc

func InstrumentHandlerFunc(metrics []*HTTPMetric, handlerFunc http.HandlerFunc) http.HandlerFunc

func Register

func Register(n *Namespace)

Register adds all the metrics in the provided namespace to the global metrics registry

func StartTimer

func StartTimer(timer Timer) (done func())

StartTimer begins a timer observation at the callsite. When the target operation is completed, the caller should call the return done func().

type Counter

Counter is a metrics that can only increment its current count

type Counter interface {
    // Inc adds Sum(vs) to the counter. Sum(vs) must be positive.
    //
    // If len(vs) == 0, increments the counter by 1.
    Inc(vs ...float64)
}

type Gauge

Gauge is a metric that allows incrementing and decrementing a value

type Gauge interface {
    Inc(...float64)
    Dec(...float64)

    // Add adds the provided value to the gauge's current value
    Add(float64)

    // Set replaces the gauge's current value with the provided value
    Set(float64)
}

type HTTPHandlerOpts

HTTPHandlerOpts describes a set of configurable options of http metrics

type HTTPHandlerOpts struct {
    DurationBuckets     []float64
    RequestSizeBuckets  []float64
    ResponseSizeBuckets []float64
}

type HTTPMetric

type HTTPMetric struct {
    prometheus.Collector
    // contains filtered or unexported fields
}

type LabeledCounter

LabeledCounter is counter that must have labels populated before use.

type LabeledCounter interface {
    WithValues(vs ...string) Counter
}

type LabeledGauge

LabeledGauge describes a gauge the must have values populated before use.

type LabeledGauge interface {
    WithValues(labels ...string) Gauge
}

type LabeledTimer

LabeledTimer is a timer that must have label values populated before use.

type LabeledTimer interface {
    WithValues(labels ...string) *labeledTimerObserver
}

type Labels

type Labels map[string]string

type Namespace

Namespace describes a set of metrics that share a namespace and subsystem.

type Namespace struct {
    // contains filtered or unexported fields
}

func NewNamespace

func NewNamespace(name, subsystem string, labels Labels) *Namespace

NewNamespace returns a namespaces that is responsible for managing a collection of metrics for a particual namespace and subsystem

labels allows const labels to be added to all metrics created in this namespace and are commonly used for data like application version and git commit

func (*Namespace) Add

func (n *Namespace) Add(collector prometheus.Collector)

func (*Namespace) Collect

func (n *Namespace) Collect(ch chan<- prometheus.Metric)

func (*Namespace) Describe

func (n *Namespace) Describe(ch chan<- *prometheus.Desc)

func (*Namespace) NewCounter

func (n *Namespace) NewCounter(name, help string) Counter

func (*Namespace) NewDefaultHttpMetrics

func (n *Namespace) NewDefaultHttpMetrics(handlerName string) []*HTTPMetric

func (*Namespace) NewDesc

func (n *Namespace) NewDesc(name, help string, unit Unit, labels ...string) *prometheus.Desc

func (*Namespace) NewGauge

func (n *Namespace) NewGauge(name, help string, unit Unit) Gauge

func (*Namespace) NewHttpMetrics

func (n *Namespace) NewHttpMetrics(handlerName string, durationBuckets, requestSizeBuckets, responseSizeBuckets []float64) []*HTTPMetric

func (*Namespace) NewHttpMetricsWithOpts

func (n *Namespace) NewHttpMetricsWithOpts(handlerName string, opts HTTPHandlerOpts) []*HTTPMetric

func (*Namespace) NewInFlightGaugeMetric

func (n *Namespace) NewInFlightGaugeMetric(handlerName string) *HTTPMetric

func (*Namespace) NewLabeledCounter

func (n *Namespace) NewLabeledCounter(name, help string, labels ...string) LabeledCounter

func (*Namespace) NewLabeledGauge

func (n *Namespace) NewLabeledGauge(name, help string, unit Unit, labels ...string) LabeledGauge

func (*Namespace) NewLabeledTimer

func (n *Namespace) NewLabeledTimer(name, help string, labels ...string) LabeledTimer

func (*Namespace) NewRequestDurationMetric

func (n *Namespace) NewRequestDurationMetric(handlerName string, buckets []float64) *HTTPMetric

func (*Namespace) NewRequestSizeMetric

func (n *Namespace) NewRequestSizeMetric(handlerName string, buckets []float64) *HTTPMetric

func (*Namespace) NewRequestTotalMetric

func (n *Namespace) NewRequestTotalMetric(handlerName string) *HTTPMetric

func (*Namespace) NewResponseSizeMetric

func (n *Namespace) NewResponseSizeMetric(handlerName string, buckets []float64) *HTTPMetric

func (*Namespace) NewTimer

func (n *Namespace) NewTimer(name, help string) Timer

func (*Namespace) WithConstLabels

func (n *Namespace) WithConstLabels(labels Labels) *Namespace

WithConstLabels returns a namespace with the provided set of labels merged with the existing constant labels on the namespace.

Only metrics created with the returned namespace will get the new constant
labels.  The returned namespace must be registered separately.

type Timer

Timer is a metric that allows collecting the duration of an action in seconds

type Timer interface {
    // Update records an observation, duration, and converts to the target
    // units.
    Update(duration time.Duration)

    // UpdateSince will add the duration from the provided starting time to the
    // timer's summary with the precisions that was used in creation of the timer
    UpdateSince(time.Time)
}

type Unit

Unit represents the type or precision of a metric that is appended to the metrics fully qualified name

type Unit string
const (
    Nanoseconds Unit = "nanoseconds"
    Seconds     Unit = "seconds"
    Bytes       Unit = "bytes"
    Total       Unit = "total"
)