Documentation
¶
Overview ¶
Package metric implements routines for generating and saving metrics associated with servers and clients.
Index ¶
Examples ¶
Constants ¶
const SaveQueueLength = 1024
SaveQueueLength is the size of the queue of metrics to be saved. Too large a queue might be wasteful and too little means metrics start to take time in the critical path of instrumented services.
Variables ¶
This section is empty.
Functions ¶
func RegisterSaver ¶
func RegisterSaver(saver Saver)
RegisterSaver registers a Saver for storing Metrics onto a backend. Only one Saver may exist or it panics.
Types ¶
type Metric ¶
Metric is a named collection of spans. A span measures time from the beginning of an event (for example, an RPC request) until its completion.
Example ¶
package main import ( "upspin.io/metric" ) func main() { // In method Lookup: m := metric.New("Dirserver") s := m.StartSpan("Lookup") defer m.Done() // do some work ... // ... and call getRoot, passing s to it: ss := s.StartSpan("getRoot") defer ss.End() // do work ... // return // Should log metric DirServer.Lookup // with a sub-span for getRoot covering part of the Lookup span. }
Output:
func New ¶
New creates a new named metric. If name is non-empty, it will prefix every descendant's Span name.
func (*Metric) Done ¶
func (m *Metric) Done()
Done ends the metric and any not-yet-ended span and saves it to stable storage. Further use of the metric or any of its spans or subspans are invalid and may produce erroneous results or be silently dropped.
type Saver ¶
type Saver interface { // Register informs the Saver that new Metrics will be added to queue. Register(queue chan *Metric) }
Saver is the common interface that all implementation-specific backends must implement for saving a Metric to a backend. A Saver must continuously process Metrics sent over a channel, set during registration.
type Span ¶
type Span struct { Name errors.Op StartTime time.Time EndTime time.Time Kind Kind // Server, Client or Other kind of metric span. Parent *Metric // parent of this span; may be nil. ParentSpan *Span // may be nil. Annotation string // optional. }
A Span measures time from the beginning of an event (for example, an RPC request) until its completion.
func (*Span) End ¶
End marks the end time of the span as the current time. It returns the parent metric for convenience which may be nil if the metric is Done.
func (*Span) Metric ¶
Metric returns the parent metric of the span. It may be nil if the metric is Done.
func (*Span) SetAnnotation ¶
SetAnnotation sets a custom annotation to the span s and returns it. If multiple annotations are set, the last one wins.