metrics

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 3 Imported by: 141

Documentation

Overview

Package metrics provides a unified interface for different metrics backends (prometheus etc.).

Index

Constants

This section is empty.

Variables

View Source
var CtxScopeKey = ctxScopeKey{}
View Source
var ErrImplemented = errors.New("there is implemenation already injected")

Functions

func Active

func Active() bool

func CtxGetScope

func CtxGetScope(ctx context.Context) string

func CtxScope

func CtxScope(ctx context.Context, scope string) context.Context

func CtxSubScope

func CtxSubScope(ctx context.Context, subscope string) context.Context

func InjectImpl

func InjectImpl(newimpl InternalNew) error

Types

type Counter

type Counter interface {
	Inc()
	Add(float64) // Only positive
}

Counter is a metric that can only be incremented.

type CounterVec added in v0.1.0

type CounterVec interface {
	WithLabelValues(lvs ...string) Counter
}

CounterVec is a counter with tags.

type Creator

type Creator interface {
	Counter() Counter
	CounterVec(labelNames []string) CounterVec
	Gauge() Gauge
	Histogram(buckets []float64) Histogram

	// opts cannot be nil, use empty summary instance
	Summary(opts SummaryOpts) Summary
}

Creator can be used to create different types of metrics.

func New

func New(name, helptext string) Creator

New returns a Creator. Name is a dot separated path which must be unique. Examples: ipfs.blockstore.bloomcache.bloom.miss.total ipfs.routing.dht.notresuingstream.total

Both arguemnts are mandatory.

func NewCtx

func NewCtx(ctx context.Context, name, helptext string) Creator

NewCtx is like New but obtains the metric scope from the given context.

type Gauge

type Gauge interface {
	Set(float64) // Introduced discontinuity
	Inc()
	Dec()
	Add(float64)
	Sub(float64)
}

Gauge is a metric that can be increased and decreased.

type Histogram

type Histogram interface {
	Observe(float64) // Adds observation to Histogram
}

Histogram metric.

type InternalNew

type InternalNew func(string, string) Creator

type Summary

type Summary interface {
	Observe(float64) // Adds observation to Summary
}

type SummaryOpts

type SummaryOpts struct {
	Objectives map[float64]float64
	MaxAge     time.Duration
	AgeBuckets uint32
	BufCap     uint32
}

SummaryOpts allow specifying options for Summary. See: http://godoc.org/github.com/prometheus/client_golang/prometheus#SummaryOpts .

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL