Documentation
¶
Index ¶
- Constants
- func AddCounter(name string, tgs Tags) uint32
- func AddFloatGauge(name string, tgs Tags) uint32
- func AddHistogram(name string, sampled bool, tgs Tags) uint32
- func AddIntGauge(name string, tgs Tags) uint32
- func IncCounter(id uint32)
- func IncCounterBy(id uint32, amount uint64)
- func ObserveHist(id uint32, value uint64)
- func RegisterBulkCallback(bcb BulkCallback)
- func RegisterFloatGaugeCallback(name string, tgs Tags, cb FloatGaugeCallback)
- func RegisterIntGaugeCallback(name string, tgs Tags, cb IntGaugeCallback)
- func SetFloatGauge(id uint32, value float64)
- func SetIntGauge(id uint32, value uint64)
- func SetPrefix(p string)
- type BulkCallback
- type FloatGaugeCallback
- type FloatMetric
- type IntGaugeCallback
- type IntMetric
- type Tags
Constants ¶
const ( TagMetricType = "type" MetricTypeCounter = "counter" MetricTypeGauge = "gauge" TagDataType = "dataType" DataTypeUint64 = "uint64" DataTypeFloat64 = "float64" TagStatistic = "statistic" )
Variables ¶
This section is empty.
Functions ¶
func AddCounter ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetFloatGauge sets a gauge by the ID returned from AddFloatGauge to the value given.
func SetIntGauge ¶
SetIntGauge sets a gauge by the ID returned from AddIntGauge to the value given.
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 IntGaugeCallback ¶
type IntGaugeCallback func() uint64
IntGaugeCallback defines a function that the metrics package can use to retrieve an integer gauge value