stats

package
v0.0.0-...-45d3652 Latest Latest
Warning

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

Go to latest
Published: May 3, 2016 License: BSD-3-Clause, MIT Imports: 0 Imported by: 0

README

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

View Source
var NoOpEnd = noOpEnd{}

NoOpEnd provides a dummy value for use in tests as valid return value for BumpTime().

Functions

func BumpAvg

func BumpAvg(c Client, key string, val float64)

BumpAvg calls BumpAvg on the Client if it isn't nil. This is useful when a component has an optional stats.Client.

func BumpHistogram

func BumpHistogram(c Client, key string, val float64)

BumpHistogram calls BumpHistogram on the Client if it isn't nil. This is useful when a component has an optional stats.Client.

func BumpSum

func BumpSum(c Client, key string, val float64)

BumpSum calls BumpSum on the Client if it isn't nil. This is useful when a component has an optional stats.Client.

func BumpTime

func BumpTime(c Client, key string) interface {
	End()
}

BumpTime calls BumpTime on the Client if it isn't nil. If the Client is nil it still returns a valid return value which will be a no-op. 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

func PrefixClient(prefixes []string, client Client) Client

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.

Jump to

Keyboard shortcuts

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