Documentation
¶
Overview ¶
Package stats exposes tools for producing application performance metrics to various metric collection backends.
Index ¶
- Constants
- Variables
- func Add(name string, value interface{}, tags ...Tag)
- func AddAt(time time.Time, name string, value interface{}, tags ...Tag)
- func ContextAddTags(ctx context.Context, tags ...Tag) bool
- func ContextWithTags(ctx context.Context, tags ...Tag) context.Context
- func Flush()
- func Incr(name string, tags ...Tag)
- func IncrAt(time time.Time, name string, tags ...Tag)
- func Observe(name string, value interface{}, tags ...Tag)
- func ObserveAt(time time.Time, name string, value interface{}, tags ...Tag)
- func Register(handler Handler)
- func Report(metrics interface{}, tags ...Tag)
- func ReportAt(time time.Time, metrics interface{}, tags ...Tag)
- func Set(name string, value interface{}, tags ...Tag)
- func SetAt(time time.Time, name string, value interface{}, tags ...Tag)
- func TagsAreSorted(tags []Tag) bool
- type Buffer
- type Clock
- type Engine
- type Field
- type FieldType
- type Flusher
- type Handler
- type HandlerFunc
- type HistogramBuckets
- type Key
- type Measure
- type Serializer
- type Tag
- type Type
- type Value
Constants ¶
FieldType constants (see same-named constants in stats/v5).
const ( Null = statsv5.Null Bool = statsv5.Bool Int = statsv5.Int Uint = statsv5.Uint Float = statsv5.Float Duration = statsv5.Duration Invalid = statsv5.Invalid )
Type constants. See same-named constants in stats/v5.
Variables ¶
var Buckets = HistogramBuckets{}
Buckets is a registry where histogram buckets are placed. Some metric collection backends need to have histogram buckets defined by the program (like Prometheus), a common pattern is to use the init function of a package to register buckets for the various histograms that it produces.
var DefaultEngine = statsv5.DefaultEngine
DefaultEngine behaves like stats/v5.DefaultEngine.
var Discard = statsv5.Discard
Discard behaves like stats/v5.Discard.
Functions ¶
func AddAt ¶
AddAt behaves like stats/v5.AddAt.
func ContextAddTags ¶
ContextAddTags adds the given tags to the given context, if the tags have been set on any of the ancestor contexts. ContextAddTags returns true if tags were successfully appended to the context, and false otherwise.
The proper way to set tags on a context if you don't know whether or not tags already exist on the context is to first call ContextAddTags, and if that returns false, then call ContextWithTags instead.
func ContextWithTags ¶
ContextWithTags returns a new child context with the given tags. If the parent context already has tags set on it, they are _not_ propegated into the context children.
func IncrAt ¶
IncrAt behaves like stats/v5.IncrAt.
func Observe ¶
Observe behaves like stats/v5.Observe.
func ObserveAt ¶
ObserveAt behaves like stats/v5.ObserveAt.
func ReportAt ¶
ReportAt behaves like stats/v5.ReportAt.
func SetAt ¶
SetAt behaves like stats/v5.SetAt.
func TagsAreSorted ¶
TagsAreSorted behaves like stats/v5.TagsAreSorted.
Types ¶
type Buffer ¶
type Buffer struct { // Target size of the memory buffer where metrics are serialized. // // If left to zero, a size of 1024 bytes is used as default (this is low, // you should set this value). // // Note that if the buffer size is small, the program may generate metrics // that don't fit into the configured buffer size. In that case the buffer // will still pass the serialized byte slice to its Serializer to leave the // decision of accepting or rejecting the metrics. BufferSize int // Size of the internal buffer pool, this controls how well the buffer // performs in highly concurrent environments. If unset, 2 x GOMAXPROCS // is used as a default value. BufferPoolSize int // The Serializer used to write the measures. // // This field cannot be nil. Serializer Serializer // contains filtered or unexported fields }
Buffer is the implementation of a measure handler which uses a Serializer to serialize the metric into a memory buffer and write them once the buffer has reached a target size.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
The Clock type can be used to report statistics on durations.
Clocks are useful to measure the duration taken by sequential execution steps and therefore aren't safe to be used concurrently by multiple goroutines.
Note: Clock times are reported to datadog in seconds. See `stats/datadog/measure.go`.
func (*Clock) Stamp ¶
Stamp reports the time difference between now and the last time the method was called (or since the clock was created).
The metric produced by this method call will have a "stamp" tag set to name.
func (*Clock) StampAt ¶
StampAt reports the time difference between now and the last time the method was called (or since the clock was created).
The metric produced by this method call will have a "stamp" tag set to name.
type Engine ¶
Engine behaves like stats/v5.Engine.
func NewEngine ¶
NewEngine behaves like stats/v5.NewEngine.
func WithPrefix ¶
WithPrefix behaves like stats/v5.WithPrefix.
type Field ¶
Field behaves like stats/v5.Field.
type Handler ¶
Handler behaves like stats/v5.Handler.
func FilteredHandler ¶ added in v4.6.4
FilteredHandler behaves like stats/v5.FilteredHandler.
func MultiHandler ¶
MultiHandler behaves like stats/v5.MultiHandler.
type HandlerFunc ¶
type HandlerFunc = statsv5.HandlerFunc
HandlerFunc behaves like stats/v5.HandlerFunc.
type HistogramBuckets ¶
HistogramBuckets is a map type storing histogram buckets.
func (HistogramBuckets) Set ¶
func (b HistogramBuckets) Set(key string, buckets ...interface{})
Set sets a set of buckets to the given list of sorted values.
type Measure ¶
Measure behaves like stats/v5.Measure.
func MakeMeasures ¶
MakeMeasures behaves like stats/v5.MakeMeasures.
type Serializer ¶
type Serializer interface { io.Writer // Appends the serialized representation of the given measures into b. // // The method must not retain any of the arguments. AppendMeasures(b []byte, time time.Time, measures ...Measure) []byte }
The Serializer interface is used to abstract the logic of serializing measures.
type Tag ¶
Tag behaves like stats/v5.Tag.
func ContextTags ¶
ContextTags returns a copy of the tags on the context if they exist and nil if they don't exist.
type Value ¶
Value behaves like stats/v5.Value.
func MustValueOf ¶ added in v4.5.3
MustValueOf behaves like stats/v5.MustValueOf.