metrics

package
v0.0.0-...-2efaa0c Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

README

Metrics GoDoc

Provides a high level abstraction to instrument metrics.

By default we support the telegraf/statsd interface which supports influxdb labels.

Interface

type Fields map[string]string

// Metrics provides a way to instrument application data
type Metrics interface {
        Close() error
        Init(...Option) error
        Counter(id string) Counter
        Gauge(id string) Gauge
        Histogram(id string) Histogram
        String() string
}

type Counter interface {
        // Increment by the given value
        Incr(d uint64)
        // Decrement by the given value
        Decr(d uint64)
        // Reset the counter
        Reset()
        // Label the counter
        WithFields(f Fields) Counter
}

type Gauge interface {
        // Set the gauge value
        Set(d int64)
        // Reset the gauge
        Reset()
        // Label the gauge
        WithFields(f Fields) Gauge
}

type Histogram interface {
        // Record a timing
        Record(d int64)
        // Reset the histogram
        Reset()
        // Label the histogram
        WithFields(f Fields) Histogram
}

Supported Backends

Documentation

Overview

Package metrics is an interface for instrumentation.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultNamespace     = "micro"
	DefaultBatchInterval = time.Second * 5
)

Functions

func NewContext

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

Types

type Counter

type Counter interface {
	// Increment by the given value
	Incr(d uint64)
	// Decrement by the given value
	Decr(d uint64)
	// Reset the counter
	Reset()
	// Label the counter
	WithFields(f Fields) Counter
}

type Fields

type Fields map[string]string

type Gauge

type Gauge interface {
	// Set the gauge value
	Set(d int64)
	// Reset the gauge
	Reset()
	// Label the gauge
	WithFields(f Fields) Gauge
}

type Histogram

type Histogram interface {
	// Record a timing
	Record(d int64)
	// Reset the histogram
	Reset()
	// Label the histogram
	WithFields(f Fields) Histogram
}

type Metrics

type Metrics interface {
	Close() error
	Init(...Option) error
	Counter(id string) Counter
	Gauge(id string) Gauge
	Histogram(id string) Histogram
	// Name
	String() string
}

Metrics provides a way to instrument application data

func FromContext

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

type Option

type Option func(o *Options)

func BatchInterval

func BatchInterval(b time.Duration) Option

func Collectors

func Collectors(c ...string) Option

func Namespace

func Namespace(n string) Option

func WithFields

func WithFields(f Fields) Option

type Options

type Options struct {
	Namespace     string
	Fields        Fields
	Collectors    []string
	BatchInterval time.Duration
}

Jump to

Keyboard shortcuts

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