Documentation ¶
Overview ¶
Package stats defines a lightweight interface for collecting statistics. It doesn't provide an implementation, just the shared interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NoOpEnd = noOpEnd{}
NoOpEnd provides a dummy value for use in tests as valid return value for BumpTime().
Functions ¶
func BumpAvg ¶
BumpAvg calls BumpAvg on the Client if it isn't nil. This is useful when a component has an optional stats.Client.
func BumpHistogram ¶
BumpHistogram calls BumpHistogram on the Client if it isn't nil. This is useful when a component has an optional stats.Client.
Types ¶
type Client ¶
type Client interface { // BumpAvg bumps the average for the given key. BumpAvg(key string, val float64) // BumpSum bumps the sum for the given key. BumpSum(key string, val float64) // BumpHistogram bumps the histogram for the given key. BumpHistogram(key string, val float64) // BumpTime is a special version of BumpHistogram which is specialized for // timers. Calling it starts the timer, and it returns a value on which End() // can be called to indicate finishing the timer. A convenient way of // recording the duration of a function is calling it like such at the top of // the function: // // defer s.BumpTime("my.function").End() BumpTime(key string) interface { End() } }
Client provides methods to collection statistics.
func PrefixClient ¶
PrefixClient adds multiple keys for the same value, with each prefix added to the key and calls the underlying client.
type HookClient ¶
type HookClient struct { BumpAvgHook func(key string, val float64) BumpSumHook func(key string, val float64) BumpHistogramHook func(key string, val float64) BumpTimeHook func(key string) interface { End() } }
HookClient is useful for testing. It provides optional hooks for each expected method in the interface, which if provided will be called. If a hook is not provided, it will be ignored.
func (*HookClient) BumpAvg ¶
func (c *HookClient) BumpAvg(key string, val float64)
BumpAvg will call BumpAvgHook if defined.
func (*HookClient) BumpHistogram ¶
func (c *HookClient) BumpHistogram(key string, val float64)
BumpHistogram will call BumpHistogramHook if defined.
func (*HookClient) BumpSum ¶
func (c *HookClient) BumpSum(key string, val float64)
BumpSum will call BumpSumHook if defined.
func (*HookClient) BumpTime ¶
func (c *HookClient) BumpTime(key string) interface { End() }
BumpTime will call BumpTimeHook if defined.