metrics

package
v3.0.0-...-9d75b9b Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: Apache-2.0 Imports: 2 Imported by: 2

README

metrics

The metrics package provides a simple metrics "Reporter" interface which allows the user to submit counters, gauges and timings (along with key/value tags).

Implementations

  • Prometheus (pull): will be first
  • Prometheus (push): certainly achievable
  • InfluxDB: could quite easily be done
  • Telegraf: almost identical to the InfluxDB implementation
  • Micro: Could we provide metrics over Micro's server interface?

Todo

  • Include a handler middleware which uses the Reporter interface to generate per-request level metrics
    • Throughput
    • Errors
    • Duration

Documentation

Overview

Package metrics is for instrumentation and debugging

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(id string, value int64, tags Tags) error

Count submits a counter metric using the DefaultMetricsReporter:

func Gauge

func Gauge(id string, value float64, tags Tags) error

Gauge submits a gauge metric using the DefaultMetricsReporter:

func IsSet

func IsSet() bool

IsSet lets you know if the DefaultMetricsReporter has been set already:

func SetDefaultMetricsReporter

func SetDefaultMetricsReporter(defaultReporter Reporter)

SetDefaultMetricsReporter allows other packages (such as profiles) to set the DefaultMetricsReporter The "initialised" flag prevents this from being overwritten (because other packages may already be using it)

func Timing

func Timing(id string, value time.Duration, tags Tags) error

Timing submits a timing metric using the DefaultMetricsReporter:

Types

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 on:

func DefaultTags

func DefaultTags(value Tags) Option

DefaultTags will be added to every metric:

func Path

func Path(value string) Option

Path used to serve metrics over HTTP:

func Percentiles

func Percentiles(value []float64) Option

Percentiles defines the desired spread of statistics for histogram / timing metrics:

type Options

type Options struct {
	Address     string
	DefaultTags Tags
	Path        string
	Percentiles []float64
}

Options for metrics implementations:

func NewOptions

func NewOptions(opt ...Option) Options

NewOptions prepares a set of options:

type Reporter

type Reporter interface {
	Count(id string, value int64, tags Tags) error
	Gauge(id string, value float64, tags Tags) error
	Timing(id string, value time.Duration, tags Tags) error
}

Reporter is an interface for collecting and instrumenting metrics

var (
	// DefaultMetricsReporter implementation
	DefaultMetricsReporter Reporter
)

type Tags

type Tags map[string]string

Tags is a map of fields to add to a metric:

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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