metrics

package
v0.0.0-...-d3db570 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagMetricType = "type"

	MetricTypeCounter = "counter"
	MetricTypeGauge   = "gauge"

	TagDataType = "dataType"

	DataTypeUint64  = "uint64"
	DataTypeFloat64 = "float64"

	TagStatistic = "statistic"
)

Variables

This section is empty.

Functions

func AddCounter

func AddCounter(name string, tgs Tags) uint32

AddCounter registers a counter and returns an ID that can be used to increment it. There is a maximum of 1024 metrics, after which adding a new one will panic.

It is recommended to have AddCounter calls as var declarations in any package that uses it. E.g.:

var (
    MetricFoo = metrics.AddCounter("foo", tags{"tag1": "value"})
)

Then in code:

metrics.IncCounter(MetricFoo)

func AddFloatGauge

func AddFloatGauge(name string, tgs Tags) uint32

AddFloatGauge registers a float-based gauge and returns an ID that can be used to access it. There is a maximum of 1024 gauges, after which adding a new one will panic

func AddHistogram

func AddHistogram(name string, sampled bool, tgs Tags) uint32

AddHistogram creates a new histogram structure to record observations. The handle returned is used to record observations. There is a maximum of 1024 histograms, after which adding a new one will panic.

It is recommended to initialize all histograms in a package level var block:

var (
    // Create unsampled histogram "foo"
    HistFoo = metrics.AddHistogram("foo", false, tags{"tag1": "value"})
)

Then make observations later:

start := timer.Now()
someOperation()
end := timer.Since(start)
metrics.ObserveHist(HistFoo, uint64(end))

func AddIntGauge

func AddIntGauge(name string, tgs Tags) uint32

AddIntGauge registers an integer-based gauge and returns an ID that can be used to update it. There is a maximum of 1024 gauges, after which adding a new one will panic

func IncCounter

func IncCounter(id uint32)

IncCounter increases the specified counter by 1. Only values returned by AddCounter can be used. Arbitrary values may panic or have undefined behavior.

func IncCounterBy

func IncCounterBy(id uint32, amount uint64)

IncCounterBy increments the specified counter by the given amount. This is for situations where the count is not a one by one thing, like counting bytes in and out of a system.

func ObserveHist

func ObserveHist(id uint32, value uint64)

ObserveHist adds an observation to the given histogram. The id parameter is a handle returned by the AddHistogram method. Using numbers not returned by AddHistogram is undefined behavior and may cause a panic.

func RegisterBulkCallback

func RegisterBulkCallback(bcb BulkCallback)

RegisterBulkCallback registers a bulk callback which will be called every time metrics are requested. There is a maximum of 1024 bulk callbacks, after which adding a new one will panic.

func RegisterFloatGaugeCallback

func RegisterFloatGaugeCallback(name string, tgs Tags, cb FloatGaugeCallback)

RegisterFloatGaugeCallback registers a gauge callback which will be called every time metrics are requested. There is a maximum of 10240 float callbacks, after which adding a new one will panic.

func RegisterIntGaugeCallback

func RegisterIntGaugeCallback(name string, tgs Tags, cb IntGaugeCallback)

RegisterIntGaugeCallback registers a gauge callback which will be called every time metrics are requested. There is a maximum of 10240 int callbacks, after which adding a new one will panic.

func SetFloatGauge

func SetFloatGauge(id uint32, value float64)

SetFloatGauge sets a gauge by the ID returned from AddFloatGauge to the value given.

func SetIntGauge

func SetIntGauge(id uint32, value uint64)

SetIntGauge sets a gauge by the ID returned from AddIntGauge to the value given.

func SetPrefix

func SetPrefix(p string)

Types

type BulkCallback

type BulkCallback func() ([]IntMetric, []FloatMetric)

BulkCallback defines a function that the metrics package can use to retrieve a set of int and float metrics in bulk. Implementors are responsible for setting up tags appropriately.

The use case for this type of callback is systems that make retrieving metrics expensive. If the metrics call has to go through CGo or is only retrievable in bulk, this type of callback will allow an implementor to do so more easily than the individual callbacks.

type FloatGaugeCallback

type FloatGaugeCallback func() float64

FloatGaugeCallback defines a function that the metrics package can use to retrieve an floating point gauge value

type FloatMetric

type FloatMetric struct {
	Name string
	Val  float64
	Tgs  Tags
}

type IntGaugeCallback

type IntGaugeCallback func() uint64

IntGaugeCallback defines a function that the metrics package can use to retrieve an integer gauge value

type IntMetric

type IntMetric struct {
	Name string
	Val  uint64
	Tgs  Tags
}

type Tags

type Tags map[string]string

Jump to

Keyboard shortcuts

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