Documentation ¶
Overview ¶
Package metrics is a go library for sampling, counting and timing go code to be output in the l2met format.
Index ¶
- Variables
- func Count(name string, v interface{}) error
- func Measure(name string, v interface{}, units string) error
- func Runtime()
- func Sample(name string, v interface{}, units string) error
- func SampleEvery(t time.Duration)
- type Drainer
- type Formatter
- type LocalStoreDrain
- type LogDrain
- type Metric
- type Namespace
- func (n Namespace) Count(name string, v interface{}) error
- func (n Namespace) CountMetric(name string, v interface{}) Metric
- func (n Namespace) Measure(name string, v interface{}, units string) error
- func (n Namespace) MeasureMetric(name string, v interface{}, units string) Metric
- func (n Namespace) NewMetric(t, name string, v interface{}, units string) Metric
- func (n Namespace) Sample(name string, v interface{}, units string) error
- func (n Namespace) SampleMetric(name string, v interface{}, units string) Metric
- func (n Namespace) Time(name string) *Timer
- type NullDrain
- type RuntimeSample
- type StatsdClient
- type StatsdDrain
- type Timer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ValueInvalidErr = errors.New("value must be one of [int, uint, int32, uint32, int64, uint64]") ValueOverflowErr = errors.New("value for uint64 too large to be converted to int64") InvalidMetricTypeErr = errors.New("metric type must be one of [count, sample, measure]") )
var ( // DefaultDrain is the Drainer that will be used to drain metrics. DefaultDrain = Drainer(&LogDrain{}) // Source is the root source that these metrics are coming from. Source string // DefaultNamespace is the default namespace to output metrics. By default, // no namespace. DefaultNamespace Namespace )
var DefaultFormatter = Formatter(&l2metFormatter{})
DefaultFormatter is the default Formatter to use.
var DefaultInterval time.Duration = 30 * time.Second
DefaultInterval sets how often the metrics Runtime will sample and emit stats.
var DefaultNowFunc = func() time.Time { return time.Now() }
DefaultNowFunc is the default function returning a time.Time for "now".
Functions ¶
func Count ¶
Count logs a count metric in the root namespace.
Example ¶
Count("user.signup", 1)
Output: count#user.signup=1
func Measure ¶
Measure logs a measurement metric in the root namespace.
Example ¶
Measure("request.time.2xx", 12.14, "ms")
Output: measure#request.time.2xx=12.14ms
func Runtime ¶
func Runtime()
Runtime enters into a loop, sampling and outputing the runtime stats periodically.
func Sample ¶
Sample logs a sample metric in the root namespace.
Example ¶
Sample("goroutine", 1, "")
Output: sample#goroutine=1
func SampleEvery ¶
SampleEvery enters a loop, sampling at the specified interval
Types ¶
type LocalStoreDrain ¶
type LocalStoreDrain struct {
// contains filtered or unexported fields
}
func (*LocalStoreDrain) Drain ¶
func (d *LocalStoreDrain) Drain(m Metric) error
Drain records metrics to the local store.
func (*LocalStoreDrain) Flush ¶
func (d *LocalStoreDrain) Flush()
func (*LocalStoreDrain) Store ¶
func (d *LocalStoreDrain) Store() map[string][]Metric
type LogDrain ¶
type LogDrain struct { // Formatter to use to format the metric into a string before outputting. Formatter Formatter DrainFunc func(string) Logger *log.Logger }
LogDrain is a Drainer implementation that logs the metrics to Stdout in l2met format.
type Metric ¶
type Metric interface { // Name returns the name of the metric (e.g. request.time.2xx) Name() string // Type returns the type of metric. Type() string // Value returns the value of the metric. Value() interface{} // Units returns the units of the metric. Units() string }
Metric represents an individual count/sample/measurement and encapsulates information about it.
type Namespace ¶
type Namespace string
Namespace represents a metric prefix. (e.g. "memcached.")
func (Namespace) CountMetric ¶
CountMetric returns a new Metric for a count.
func (Namespace) MeasureMetric ¶
MeasureMetric returns a new Metric for a measure.
func (Namespace) SampleMetric ¶
SampleMetric returns a new Metric for a sample.
type RuntimeSample ¶
RuntimeSample represents a sampling of the runtime stats.
func NewRuntimeSample ¶
func NewRuntimeSample() *RuntimeSample
NewRuntimeSample samples the current runtime and returns a RuntimeSample.
type StatsdClient ¶
type StatsdDrain ¶
type StatsdDrain struct {
// contains filtered or unexported fields
}
StatsdDrain is a Drainer that records metrics to a statsd server.
func NewStatsdDrain ¶
func NewStatsdDrain(c StatsdClient, tmpl string) (*StatsdDrain, error)
NewStatsdDrain takes a statsd client and a template string. The template string is used to construct the metric name with a Metric as its context.
func (*StatsdDrain) Drain ¶
func (d *StatsdDrain) Drain(m Metric) error
Drain records metrics to a statsd server.
type Timer ¶
type Timer struct { // NowFunc is a function to return a time.Time representing "now". Zero value // is DefaultNowFunc. NowFunc func() time.Time // contains filtered or unexported fields }
Timer is an implementation of the Metric interface for timing things.
func Time ¶
Time starts a timer and returns it.
Example ¶
t := Time("request.time") t.NowFunc = func() time.Time { return t.start.Add(527 * time.Millisecond) } t.Done()
Output: measure#request.time=527ms
func (*Timer) Milliseconds ¶
Milliseconds returns the number of milliseconds elapsed.