Documentation
¶
Overview ¶
Package instruments allows you to collects metrics over discrete time intervals.
Collected metrics will only reflect observations from last time window only, rather than including observations from prior windows, contrary to EWMA based metrics.
timer := instruments.NewTimer(-1) registry := reporter.NewRegistry() registry.Register("processing-time", timer) go reporter.Log("process", registry, time.Minute) timer.Time(func() { ... })
Instruments support two types of instruments: Discrete instruments return a single value, and Sample instruments a sorted array of values.
Theses base instruments are available:
- Counter: holds a counter that can be incremented or decremented.
- Rate: tracks the rate of values per seconds.
- Reservoir: randomly samples values.
- Derive: tracks the rate of values based on the delta with previous value.
- Gauge: tracks last value.
- Timer: tracks durations.
You can create custom instruments or compose new instruments form the built-in instruments as long as they implements the Sample or Discrete interfaces.
Registry enforce the Discrete and Sample interfaces, creating a custom Reporter should be trivial, for example:
for k, m := range registry.Instruments() { switch i := m.(type) { case instruments.Discrete: s := i.Snapshot() report(k, s) case instruments.Sample: s := instruments.Quantile(i.Snapshot(), 0.95) report(k, s) } }
Index ¶
- func Ceil(v float64) int64
- func Floor(v float64) int64
- func Max(values []int64) int64
- func Mean(values []int64) float64
- func Min(values []int64) int64
- func Quantile(v []int64, q float64) int64
- func Scale(o, d time.Duration) float64
- func StandardDeviation(v []int64) float64
- func Variance(values []int64) float64
- type Counter
- type Derive
- type Discrete
- type Gauge
- type Rate
- type Reservoir
- type Sample
- type Timer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StandardDeviation ¶
StandardDeviation returns standard deviation of the given sample.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter holds a counter that can be incremented or decremented.
Example ¶
counter := NewCounter() counter.Update(20) counter.Update(25) s := counter.Snapshot() fmt.Println(s)
Output:
type Derive ¶
type Derive struct {
// contains filtered or unexported fields
}
Derive tracks the rate of deltas per seconds.
Example ¶
derive := NewDerive(34) derive.Update(56) derive.Update(78) s := derive.Snapshot() fmt.Println(s)
Output:
func NewDeriveScale ¶
NewDeriveScale creates a new derive instruments with the given unit.
type Discrete ¶
type Discrete interface {
Snapshot() int64
}
Discrete represents a single value instrument.
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge tracks a value.
Example ¶
gauge := NewGauge(34) gauge.Update(35) s := gauge.Snapshot() fmt.Println(s)
Output:
type Rate ¶
type Rate struct {
// contains filtered or unexported fields
}
Rate tracks the rate of values per second.
Example ¶
rate := NewRate() rate.Update(20) rate.Update(25) s := rate.Snapshot() fmt.Println(s)
Output:
func NewRateScale ¶
NewRateScale creates a new rate instruments with the given unit.
type Reservoir ¶
type Reservoir struct {
// contains filtered or unexported fields
}
Reservoir tracks a sample of values.
Example ¶
reservoir := NewReservoir(-1) reservoir.Update(12) reservoir.Update(54) reservoir.Update(34) s := reservoir.Snapshot() fmt.Println(Quantile(s, 0.99))
Output:
func NewReservoir ¶
NewReservoir creates a new reservoir of the given size. If size is negative, it will create a sample of DefaultReservoirSize size.
func (*Reservoir) Update ¶
Update fills the sample randomly with given value, for reference, see: http://en.wikipedia.org/wiki/Reservoir_sampling
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer tracks durations.
Example ¶
timer := NewTimer(-1) ts := time.Now() time.Sleep(10 * time.Second) timer.Since(ts) s := timer.Snapshot() fmt.Println(Quantile(s, 0.99))
Output:
Directories
¶
Path | Synopsis |
---|---|
Package reporter provides default reporting functionnality.
|
Package reporter provides default reporting functionnality. |
Package runtime provides runtime instrumentations around memory usage, goroutine and cgo calls.
|
Package runtime provides runtime instrumentations around memory usage, goroutine and cgo calls. |