metrics

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 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 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"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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