Documentation ¶
Overview ¶
bucket.go provides fundamental interface expectations for various bucket types.
constants.go provides package-level constants for metrics.
The metrics package provides general descriptors for the concept of exportable metrics.
accumulating_bucket.go provides a histogram bucket type that accumulates elements until a given capacity and enacts a given eviction policy upon such a condition.
accumulating_bucket_test.go provides a test complement for the accumulating_bucket_go module.
eviction.go provides several histogram bucket eviction strategies.
eviction_test.go provides a test complement for the eviction.go module.
gauge.go provides a scalar metric that one can monitor. It is useful for certain cases, such as instantaneous temperature.
gauge_test.go provides a test complement for the gauge.go module.
histogram.go provides a basic histogram metric, which can accumulate scalar event values or samples. The underlying histogram implementation is designed to be performant in that it accepts tolerable inaccuracies.
histogram_test.go provides a test complement for the histogram.go module.
metric.go provides fundamental interface expectations for the various metrics.
metrics_test.go provides a test suite for all tests in the metrics package hierarchy. It employs the gocheck framework for test scaffolding.
tallying_bucket.go provides a histogram bucket type that aggregates tallies of events that fall into its ranges versus a summary of the values themselves.
tallying_bucket_test.go provides a test complement for the tallying_bucket.go module.
timer.go provides a scalar metric that times how long a given event takes.
timer_test.go provides a test complement for the timer.go module.
Index ¶
- func EquallySizedBucketsFor(lower, upper float64, count int) []float64
- func InstrumentCall(instrumentable InstrumentableCall, onCompletion CompletionCallback) time.Duration
- func LogarithmicSizedBucketsFor(lower, upper float64) []float64
- type AccumulatingBucket
- type Bucket
- type BucketBuilder
- type CompletionCallback
- type EvictionPolicy
- type GaugeMetric
- func (metric *GaugeMetric) Decrement() float64
- func (metric *GaugeMetric) DecrementBy(value float64) float64
- func (metric *GaugeMetric) Get() float64
- func (metric *GaugeMetric) Humanize() string
- func (metric *GaugeMetric) Increment() float64
- func (metric *GaugeMetric) IncrementBy(value float64) float64
- func (metric *GaugeMetric) Marshallable() map[string]interface{}
- func (metric *GaugeMetric) Set(value float64) float64
- type Histogram
- type HistogramSpecification
- type InstrumentableCall
- type Metric
- type StopWatch
- type TallyingBucket
- type TallyingIndexEstimator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EquallySizedBucketsFor ¶
This generates count-buckets of equal size distributed along the open interval of lower to upper. For instance, {lower=0, upper=10, count=5} yields the following: [0, 2, 4, 6, 8].
func InstrumentCall ¶
func InstrumentCall(instrumentable InstrumentableCall, onCompletion CompletionCallback) time.Duration
Provide a quick way of instrumenting a InstrumentableCall and emitting its duration.
func LogarithmicSizedBucketsFor ¶
This generates log2-sized buckets spanning from lower to upper inclusively as well as values beyond it.
Types ¶
type AccumulatingBucket ¶
type AccumulatingBucket struct {
// contains filtered or unexported fields
}
func (*AccumulatingBucket) Add ¶
func (b *AccumulatingBucket) Add(value float64)
Add a value to the bucket. Depending on whether the bucket is full, it may trigger an eviction of older items.
func (*AccumulatingBucket) Humanize ¶
func (b *AccumulatingBucket) Humanize() string
func (*AccumulatingBucket) Observations ¶
func (b *AccumulatingBucket) Observations() int
func (*AccumulatingBucket) ValueForIndex ¶
func (b *AccumulatingBucket) ValueForIndex(index int) float64
type Bucket ¶
type Bucket interface { /* Add a value to the bucket. */ Add(value float64) /* Provide a humanized representation hereof. */ Humanize() string /* Provide a count of observations throughout the bucket's lifetime. */ Observations() int /* Provide the value from the given in-memory value cache or an estimate thereof for the given index. The consumer of the bucket's data makes no assumptions about the underlying storage mechanisms that the bucket employs. */ ValueForIndex(index int) float64 }
This defines the base Bucket type. The exact behaviors of the bucket are at the whim of the implementor.
A Bucket is used as a container by Histogram as a collection for its accumulated samples.
type BucketBuilder ¶
type BucketBuilder func() Bucket
The Histogram class and associated types build buckets on their own.
func AccumulatingBucketBuilder ¶
func AccumulatingBucketBuilder(evictionPolicy EvictionPolicy, maximumSize int) BucketBuilder
AccumulatingBucketBuilder is a convenience method for generating a BucketBuilder that produces AccumatingBucket entries with a certain behavior set.
type CompletionCallback ¶
This callback is called upon the completion of the timer—i.e., when it stops.
type EvictionPolicy ¶
EvictionPolicy implements some sort of garbage collection methodology for an underlying heap.Interface. This is presently only used for AccumulatingBucket.
func EvictAndReplaceWith ¶
func EvictAndReplaceWith(count int, reducer maths.ReductionMethod) EvictionPolicy
This factory produces an EvictionPolicy that applies some standardized reduction methodology on the to-be-terminated values.
func EvictOldest ¶
func EvictOldest(count int) EvictionPolicy
As the name implies, this evicts the oldest x objects from the heap.
type GaugeMetric ¶
type GaugeMetric struct {
// contains filtered or unexported fields
}
A gauge metric merely provides an instantaneous representation of a scalar value or an accumulation. For instance, if one wants to expose the current temperature or the hitherto bandwidth used, this would be the metric for such circumstances.
func (*GaugeMetric) Decrement ¶
func (metric *GaugeMetric) Decrement() float64
func (*GaugeMetric) DecrementBy ¶
func (metric *GaugeMetric) DecrementBy(value float64) float64
func (*GaugeMetric) Get ¶
func (metric *GaugeMetric) Get() float64
func (*GaugeMetric) Humanize ¶
func (metric *GaugeMetric) Humanize() string
func (*GaugeMetric) Increment ¶
func (metric *GaugeMetric) Increment() float64
func (*GaugeMetric) IncrementBy ¶
func (metric *GaugeMetric) IncrementBy(value float64) float64
func (*GaugeMetric) Marshallable ¶
func (metric *GaugeMetric) Marshallable() map[string]interface{}
func (*GaugeMetric) Set ¶
func (metric *GaugeMetric) Set(value float64) float64
type Histogram ¶
type Histogram struct {
// contains filtered or unexported fields
}
The histogram is an accumulator for samples. It merely routes into which to bucket to capture an event and provides a percentile calculation mechanism.
Histogram makes do without locking by employing the law of large numbers to presume a convergence toward a given bucket distribution. Locking may be implemented in the buckets themselves, though.
func CreateHistogram ¶
func CreateHistogram(specification *HistogramSpecification) *Histogram
Produce a histogram from a given specification.
func (*Histogram) Marshallable ¶
func (*Histogram) Percentile ¶
Return the histogram's estimate of the value for a given percentile of collected samples. The requested percentile is expected to be a real value within (0, 1.0].
type HistogramSpecification ¶
type HistogramSpecification struct { Starts []float64 BucketMaker BucketBuilder ReportablePercentiles []float64 }
A HistogramSpecification defines how a Histogram is to be built.
type InstrumentableCall ¶
type InstrumentableCall func()
This is meant to capture a function that a StopWatch can call for purposes of instrumentation.
type Metric ¶
type Metric interface { /* Produce a human-consumable representation of the metric. */ Humanize() string /* Produce a JSON-consumable representation of the metric. */ Marshallable() map[string]interface{} }
A Metric is something that can be exposed via the registry framework.
type StopWatch ¶
type StopWatch struct {
// contains filtered or unexported fields
}
StopWatch is the structure that captures instrumentation for durations.
N.B.(mtp): A major limitation hereof is that the StopWatch protocol cannot retain instrumentation if a panic percolates within the context that is being measured.
func Start ¶
func Start(onCompletion CompletionCallback) *StopWatch
Return a new StopWatch that is ready for instrumentation.
type TallyingBucket ¶
type TallyingBucket struct {
// contains filtered or unexported fields
}
A TallyingBucket is a Bucket that tallies when an object is added to it. Upon insertion, an object is compared against collected extrema and noted as a new minimum or maximum if appropriate.
func CustomTallyingBucket ¶
func CustomTallyingBucket(estimator TallyingIndexEstimator) TallyingBucket
func DefaultTallyingBucket ¶
func DefaultTallyingBucket() TallyingBucket
Produce a TallyingBucket with sane defaults.
func (*TallyingBucket) Add ¶
func (b *TallyingBucket) Add(value float64)
func (*TallyingBucket) Humanize ¶
func (b *TallyingBucket) Humanize() string
func (*TallyingBucket) Observations ¶
func (b *TallyingBucket) Observations() int
func (*TallyingBucket) ValueForIndex ¶
func (b *TallyingBucket) ValueForIndex(index int) float64
type TallyingIndexEstimator ¶
A TallyingIndexEstimator is responsible for estimating the value of index for a given TallyingBucket, even though a TallyingBucket does not possess a collection of samples. There are a few strategies listed below for how this value should be approximated.
var Average TallyingIndexEstimator = emptyFilter(func(minimum, maximum float64, _, observations int) float64 { return maths.Average([]float64{minimum, maximum}) })
Report the average of the extrema.
var Maximum TallyingIndexEstimator = emptyFilter(func(minimum, maximum float64, _, observations int) float64 {
return maximum
})
Report the largest observed value in the bucket.
var Minimum TallyingIndexEstimator = emptyFilter(func(minimum, maximum float64, _, observations int) float64 {
return minimum
})
Report the smallest observed value in the bucket.
var Uniform TallyingIndexEstimator = emptyFilter(func(minimum, maximum float64, index, observations int) float64 { if observations == 1 { return minimum } location := float64(index) / float64(observations) if location > upperThird { return maximum } else if location < lowerThird { return minimum } return maths.Average([]float64{minimum, maximum}) })
Report the minimum value of the index is in the lower-third of observations, the average if in the middle-third, and the maximum if in the largest third.