meter

package
v3.5.8 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

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"
	// DefaultMetricPrefix holds the string that prepends to all metrics
	DefaultMetricPrefix = "micro_"
	// DefaultLabelPrefix holds the string that prepends to all labels
	DefaultLabelPrefix = "micro_"
	// 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
)

Functions

func BuildLabels added in v3.4.10

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

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

func BuildName added in v3.4.10

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

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

func NewContext added in v3.1.5

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

NewContext put meter in context

Types

type Counter added in v3.1.4

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

Counter is a counter

type FloatCounter added in v3.1.4

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

FloatCounter is a float64 counter

type Gauge added in v3.1.4

type Gauge interface {
	Get() float64
}

Gauge is a float64 gauge

type Histogram added in v3.1.4

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

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

type Meter added in v3.1.4

type Meter interface {
	Name() string
	Init(opts ...Option) error
	Counter(name string, labels ...string) Counter
	FloatCounter(name string, labels ...string) FloatCounter
	Gauge(name string, fn func() float64, labels ...string) Gauge
	Set(opts ...Option) Meter
	Histogram(name string, labels ...string) Histogram
	Summary(name string, labels ...string) Summary
	SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) Summary
	Write(w io.Writer, opts ...Option) error
	Options() Options
	String() string
}

Meter is an interface for collecting and instrumenting metrics

func FromContext added in v3.1.5

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

FromContext get meter from context

func NewMeter added in v3.1.4

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 added in v3.1.9

func Labels(ls ...string) Option

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Name added in v3.2.1

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 added in v3.1.5

func SetOption(k, v interface{}) Option

SetOption returns a function to setup a context with given value

func WriteFDMetrics added in v3.2.12

func WriteFDMetrics(b bool) Option

WriteFDMetrics enable fd metrics output for write

func WriteProcessMetrics added in v3.2.12

func WriteProcessMetrics(b bool) Option

WriteProcessMetrics enable process metrics output for write

type Options

type Options struct {
	// Logger used for logging
	Logger logger.Logger
	// 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
	// MetricPrefix holds the prefix for all metrics
	MetricPrefix string
	// LabelPrefix holds the prefix for all labels
	LabelPrefix 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 added in v3.1.4

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

Summary is the summary

Directories

Path Synopsis
Code generated by protoc-gen-micro source: handler.proto Code generated by protoc-gen-micro source: handler.proto
Code generated by protoc-gen-micro source: handler.proto Code generated by protoc-gen-micro source: handler.proto

Jump to

Keyboard shortcuts

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