metrics

package
v0.0.0-...-1a3b581 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(config Metrics, options ...FactoryOption) error

Types

type Counter

type Counter interface {
	Loadable

	// Incr will increment the counter by 1
	Incr(ctx context.Context, opts ...MeasurementOption) error

	// Add will add the given addend to the counter
	Add(ctx context.Context, addend float64, opts ...MeasurementOption) error
}

type DefaultCounter

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

func (*DefaultCounter) Add

func (c *DefaultCounter) Add(ctx context.Context, addend float64, opts ...MeasurementOption) error

func (*DefaultCounter) Incr

func (c *DefaultCounter) Incr(ctx context.Context, opts ...MeasurementOption) error

func (*DefaultCounter) Load

func (c *DefaultCounter) Load(opts ...MeasurementOption)

type DefaultGauge

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

func (*DefaultGauge) Load

func (g *DefaultGauge) Load(opts ...MeasurementOption)

func (*DefaultGauge) Measure

func (g *DefaultGauge) Measure(ctx context.Context, value float64, opts ...MeasurementOption) error

type DefaultHistogram

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

func (*DefaultHistogram) Load

func (h *DefaultHistogram) Load(opts ...MeasurementOption)

func (*DefaultHistogram) Record

func (h *DefaultHistogram) Record(ctx context.Context, measurement float64, opts ...MeasurementOption) error

type DefaultMetricsFactory

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

func (*DefaultMetricsFactory) NewCounter

func (mf *DefaultMetricsFactory) NewCounter(name string, opts ...MetricOption) (Counter, error)

NewCounter will produce a Counter for measuring values that go up

It will create a new counter on first invocation, or return a cached counter previously created by name

func (*DefaultMetricsFactory) NewGauge

func (mf *DefaultMetricsFactory) NewGauge(name string, opts ...MetricOption) (Gauge, error)

NewGauge will produce a Gauge for setting an instantaneous value

It will create a new gauge on first invocation, or return a cached gauge previously created by name

func (*DefaultMetricsFactory) NewHistogram

func (mf *DefaultMetricsFactory) NewHistogram(name string, opts ...MetricOption) (Histogram, error)

NewHistogram will produce a Histogram for observing values

It will create a new histogram on first invocation, or return a cached histogram

type Factory

type Factory interface {
	NewCounter(name string, opts ...MetricOption) (Counter, error)
	NewHistogram(name string, opts ...MetricOption) (Histogram, error)
	NewGauge(name string, opts ...MetricOption) (Gauge, error)
}
var DefaultFactory Factory

type FactoryOption

type FactoryOption func(*factoryOpts)

func WithFactory

func WithFactory(factory Factory) FactoryOption

WithFactory allows providing a custom factory to be used as the DefaultFactory

func WithStaticLabel

func WithStaticLabel(label, value string) FactoryOption

WithStaticLabel allows setting labels that will be set on all metrics created with the factory

type Gauge

type Gauge interface {
	Loadable

	// Measure will set the Gauge to the provided value
	Measure(ctx context.Context, value float64, opts ...MeasurementOption) error
}

type Histogram

type Histogram interface {
	Loadable

	// Record will observe the measurement
	Record(ctx context.Context, measurement float64, opts ...MeasurementOption) error
}

type Loadable

type Loadable interface {
	// Load will load the Metric with the MeasurementOption provided
	Load(opts ...MeasurementOption)
}

Loadable is a behavior where measurement options can be loaded prior to measuring with the metric

type MeasurementOption

type MeasurementOption func(*metricOpts)

func WithLabel

func WithLabel(k, v string) MeasurementOption

WithLabel applies a label to the measurement being requested

If multiple WithLabel are applied with the same key, the last entry will be respected

type MetricOption

type MetricOption func(*metricOpts)

func WithDescription

func WithDescription(desc string) MetricOption

WithDescription set the description of the metric.

func WithHistogramBucketsBounds

func WithHistogramBucketsBounds(buckets ...float64) MetricOption

WithHistogramBucketsBounds allows to override the default bucket boundaries for a histogram

func WithLabelNames

func WithLabelNames(labels []string) MetricOption

WithLabelNames sets the labels expected to be provided to the metric.

Subsequent WithLabelNames will overwrite the previous set of names passed in. Labels passed in that were not provided as a LabelName will be ignored. Labels not passed in that were expected will result in an error being returned. // TODO <- This could also just fill in -?

func WithStaticLabels

func WithStaticLabels(labels map[string]string) MetricOption

WithStaticLabels set static labels which will always export by the metric

func WithUnit

func WithUnit(unit string) MetricOption

WithUnit sets units of the measurement.

The unit u should be defined using the appropriate [UCUM](https://ucum.org) case-sensitive code.

type Metrics

type Metrics struct {
	MetricsPort int    `env:"METRICS_PORT" envDefault:"8000"`
	ServiceName string `env:"SERVICE_NAME" envDefault:"_"`
	Environment string `env:"ENVIRONMENT" envDefault:"dev"`
}

Jump to

Keyboard shortcuts

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