meter

package
v3.10.98 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 14

Documentation

Overview

Package meter is for instrumentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultMeter is the default meter
	DefaultMeter Meter = NewMeter()
	// DefaultAddress data will be made available on this host:port
	DefaultAddress = ":9090"
	// DefaultPath the meter endpoint where the Meter data will be made available
	DefaultPath = "/metrics"
	// DefaultMeterStatsInterval specifies interval for meter updating
	DefaultMeterStatsInterval = 5 * time.Second
	// DefaultSummaryQuantiles is the default spread of stats for summary
	DefaultSummaryQuantiles = []float64{0.5, 0.9, 0.97, 0.99, 1}
	// DefaultSummaryWindow is the default window for summary
	DefaultSummaryWindow = 5 * time.Minute
	// DefaultSkipEndpoints is the slice of endpoint that must not be metered
	DefaultSkipEndpoints = []string{
		"MeterService.Metrics",
		"HealthService.Live",
		"HealthService.Ready",
		"HealthService.Version",
	}
)

Functions

func BuildLabels

func BuildLabels(labels ...string) []string

BuildLabels used to sort labels and delete duplicates. Last value wins in case of duplicate label keys.

func BuildName

func BuildName(name string, labels ...string) string

BuildName used to combine metric with labels. If labels count is odd, drop last element

func NewContext

func NewContext(ctx context.Context, c Meter) context.Context

NewContext put meter in context

Types

type Counter

type Counter interface {
	Add(int)
	Dec()
	Get() uint64
	Inc()
	Set(uint64)
}

Counter is a counter

type FloatCounter

type FloatCounter interface {
	Add(float64)
	Get() float64
	Set(float64)
	Sub(float64)
}

FloatCounter is a float64 counter

type Gauge

type Gauge interface {
	Get() float64
}

Gauge is a float64 gauge

type Histogram

type Histogram interface {
	Reset()
	Update(float64)
	UpdateDuration(time.Time)
}

Histogram is a histogram for non-negative values with automatically created buckets

type Meter

type Meter interface {
	// Name returns meter name
	Name() string
	// Init initialize meter
	Init(opts ...Option) error
	// Clone create meter copy with new options
	Clone(opts ...Option) Meter
	// Counter get or create counter
	Counter(name string, labels ...string) Counter
	// FloatCounter get or create float counter
	FloatCounter(name string, labels ...string) FloatCounter
	// Gauge get or create gauge
	Gauge(name string, fn func() float64, labels ...string) Gauge
	// Set create new meter metrics set
	Set(opts ...Option) Meter
	// Histogram get or create histogram
	Histogram(name string, labels ...string) Histogram
	// Summary get or create summary
	Summary(name string, labels ...string) Summary
	// SummaryExt get or create summary with spcified quantiles and window time
	SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) Summary
	// Write writes metrics to io.Writer
	Write(w io.Writer, opts ...Option) error
	// Options returns meter options
	Options() Options
	// String return meter type
	String() string
}

Meter is an interface for collecting and instrumenting metrics

func FromContext

func FromContext(ctx context.Context) (Meter, bool)

FromContext get meter from context

func NewMeter

func NewMeter(opts ...Option) Meter

NewMeter returns a configured noop reporter:

type Option

type Option func(*Options)

Option powers the configuration for metrics implementations:

func Address

func Address(value string) Option

Address is the listen address to serve metrics

func Context

func Context(ctx context.Context) Option

Context sets the metrics context

func Labels

func Labels(ls ...string) Option

Labels add the meter labels

func Name

func Name(n string) Option

Name sets the name

func Path

func Path(value string) Option

Path used to serve metrics over HTTP

func SetOption

func SetOption(k, v interface{}) Option

SetOption returns a function to setup a context with given value

func WriteFDMetrics

func WriteFDMetrics(b bool) Option

WriteFDMetrics enable fd metrics output for write

func WriteProcessMetrics

func WriteProcessMetrics(b bool) Option

WriteProcessMetrics enable process metrics output for write

type Options

type Options struct {
	// Context holds external options
	Context context.Context
	// Name holds the meter name
	Name string
	// Address holds the address that serves metrics
	Address string
	// Path holds the path for metrics
	Path string
	// Labels holds the default labels
	Labels []string
	// WriteProcessMetrics flag to write process metrics
	WriteProcessMetrics bool
	// WriteFDMetrics flag to write fd metrics
	WriteFDMetrics bool
}

Options for metrics implementations

func NewOptions

func NewOptions(opt ...Option) Options

NewOptions prepares a set of options:

type Summary

type Summary interface {
	Update(float64)
	UpdateDuration(time.Time)
}

Summary is the summary

Jump to

Keyboard shortcuts

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