Documentation ¶
Index ¶
- Constants
- Variables
- func KeyForPrefixedStringMap(prefix string, stringMap map[string]string) string
- func KeyForStringMap(stringMap map[string]string) string
- func NoOpSanitizeFn(v string) string
- type BaseStatsReporter
- type BucketPair
- type Buckets
- type CachedCount
- type CachedGauge
- type CachedHistogram
- type CachedHistogramBucket
- type CachedStatsReporter
- type CachedTimer
- type Capabilities
- type Counter
- type CounterSnapshot
- type DurationBuckets
- func ExponentialDurationBuckets(start time.Duration, factor float64, n int) (DurationBuckets, error)
- func LinearDurationBuckets(start, width time.Duration, n int) (DurationBuckets, error)
- func MustMakeExponentialDurationBuckets(start time.Duration, factor float64, n int) DurationBuckets
- func MustMakeLinearDurationBuckets(start, width time.Duration, n int) DurationBuckets
- type Gauge
- type GaugeSnapshot
- type Histogram
- type HistogramSnapshot
- type InternalMetricOption
- type ObjectPool
- type SanitizeFn
- type SanitizeOptions
- type SanitizeRange
- type Sanitizer
- type Scope
- type ScopeOptions
- type Snapshot
- type StatsReporter
- type Stopwatch
- type StopwatchRecorder
- type TestScope
- type Timer
- type TimerSnapshot
- type ValidCharacters
- type ValueBuckets
- func ExponentialValueBuckets(start, factor float64, n int) (ValueBuckets, error)
- func LinearValueBuckets(start, width float64, n int) (ValueBuckets, error)
- func MustMakeExponentialValueBuckets(start, factor float64, n int) ValueBuckets
- func MustMakeLinearValueBuckets(start, width float64, n int) ValueBuckets
Constants ¶
const Version = "4.1.8"
Version is the current version of the library.
Variables ¶
var ( // DefaultReplacementCharacter is the default character used for // replacements. DefaultReplacementCharacter = '_' // AlphanumericRange is the range of alphanumeric characters. AlphanumericRange = []SanitizeRange{ {rune('a'), rune('z')}, {rune('A'), rune('Z')}, {rune('0'), rune('9')}} // UnderscoreCharacters is just an underscore character. UnderscoreCharacters = []rune{ '_'} // UnderscoreDashCharacters is a slice of underscore, and // dash characters. UnderscoreDashCharacters = []rune{ '-', '_'} // UnderscoreDashDotCharacters is a slice of underscore, // dash, and dot characters. UnderscoreDashDotCharacters = []rune{ '.', '-', '_'} )
var (
// NoopScope is a scope that does nothing
NoopScope, _ = NewRootScope(ScopeOptions{Reporter: NullStatsReporter}, 0)
// DefaultSeparator is the default separator used to join nested scopes
DefaultSeparator = "."
)
var NewStopwatch = ubertally.NewStopwatch
Functions ¶
func KeyForPrefixedStringMap ¶
KeyForPrefixedStringMap generates a unique key for a a prefix and a map string set combination.
func KeyForStringMap ¶
KeyForStringMap generates a unique key for a map string set combination.
func NoOpSanitizeFn ¶
NoOpSanitizeFn returns the input un-touched.
Types ¶
type BaseStatsReporter ¶
type BaseStatsReporter interface { // Capabilities returns the capabilities description of the reporter. Capabilities() Capabilities // Flush asks the reporter to flush all reported values. Flush() }
BaseStatsReporter implements the shared reporter methods.
type BucketPair ¶
type BucketPair = ubertally.BucketPair
BucketPair describes the lower and upper bounds for a derived bucket from a buckets set.
func BucketPairs ¶
func BucketPairs(buckets Buckets) []BucketPair
BucketPairs creates a set of bucket pairs from a set of buckets describing the lower and upper bounds for each derived bucket.
type Buckets ¶
Buckets is an interface that can represent a set of buckets either as float64s or as durations.
var ( // DefaultBuckets can be passed to specify to default buckets. DefaultBuckets Buckets )
type CachedCount ¶
type CachedCount interface {
ReportCount(value int64)
}
CachedCount interface for reporting an individual counter
type CachedGauge ¶
type CachedGauge interface {
ReportGauge(value float64)
}
CachedGauge interface for reporting an individual gauge
type CachedHistogram ¶
type CachedHistogram interface { ValueBucket( bucketLowerBound, bucketUpperBound float64, ) CachedHistogramBucket DurationBucket( bucketLowerBound, bucketUpperBound time.Duration, ) CachedHistogramBucket }
CachedHistogram interface for reporting histogram samples to buckets
type CachedHistogramBucket ¶
type CachedHistogramBucket interface {
ReportSamples(value int64)
}
CachedHistogramBucket interface for reporting histogram samples to a specific bucket
type CachedStatsReporter ¶
type CachedStatsReporter interface { BaseStatsReporter // AllocateCounter pre allocates a counter data structure with name & tags. AllocateCounter( name string, tags map[string]string, ) CachedCount // AllocateGauge pre allocates a gauge data structure with name & tags. AllocateGauge( name string, tags map[string]string, ) CachedGauge // AllocateTimer pre allocates a timer data structure with name & tags. AllocateTimer( name string, tags map[string]string, ) CachedTimer // AllocateHistogram pre allocates a histogram data structure with name, tags, // value buckets and duration buckets. AllocateHistogram( name string, tags map[string]string, buckets Buckets, ) CachedHistogram }
CachedStatsReporter is a backend for Scopes that pre allocates all counter, gauges, timers & histograms. This is harder to implement but more performant.
type CachedTimer ¶
CachedTimer interface for reporting an individual timer
type Capabilities ¶
type Capabilities = ubertally.Capabilities
Capabilities is a description of metrics reporting capabilities.
type CounterSnapshot ¶
type CounterSnapshot interface { // Name returns the name Name() string // Tags returns the tags Tags() map[string]string // Value returns the value Value() int64 }
CounterSnapshot is a snapshot of a counter
type DurationBuckets ¶
DurationBuckets is a set of time.Duration values that implements Buckets.
func ExponentialDurationBuckets ¶
func ExponentialDurationBuckets(start time.Duration, factor float64, n int) (DurationBuckets, error)
ExponentialDurationBuckets creates a set of exponential duration buckets.
func LinearDurationBuckets ¶
func LinearDurationBuckets(start, width time.Duration, n int) (DurationBuckets, error)
LinearDurationBuckets creates a set of linear duration buckets.
func MustMakeExponentialDurationBuckets ¶
func MustMakeExponentialDurationBuckets(start time.Duration, factor float64, n int) DurationBuckets
MustMakeExponentialDurationBuckets creates a set of exponential value buckets or panics.
func MustMakeLinearDurationBuckets ¶
func MustMakeLinearDurationBuckets(start, width time.Duration, n int) DurationBuckets
MustMakeLinearDurationBuckets creates a set of linear duration buckets. or panics.
func (DurationBuckets) AsDurations ¶
func (v DurationBuckets) AsDurations() []time.Duration
AsDurations implements Buckets.
func (DurationBuckets) AsValues ¶
func (v DurationBuckets) AsValues() []float64
AsValues implements Buckets and returns float64 representations of the time.Duration values divided by time.Second.
func (DurationBuckets) Less ¶
func (v DurationBuckets) Less(i, j int) bool
Implements sort.Interface
func (DurationBuckets) String ¶
func (v DurationBuckets) String() string
type GaugeSnapshot ¶
type GaugeSnapshot interface { // Name returns the name Name() string // Tags returns the tags Tags() map[string]string // Value returns the value Value() float64 }
GaugeSnapshot is a snapshot of a gauge
type HistogramSnapshot ¶
type HistogramSnapshot interface { // Name returns the name Name() string // Tags returns the tags Tags() map[string]string // Values returns the sample values by upper bound for a valueHistogram Values() map[float64]int64 // Durations returns the sample values by upper bound for a durationHistogram Durations() map[time.Duration]int64 }
HistogramSnapshot is a snapshot of a histogram
type InternalMetricOption ¶
type InternalMetricOption int
InternalMetricOption is used to configure internal metrics.
const ( // Unset is the "no-op" config, which turns off internal metrics. Unset InternalMetricOption = iota // SendInternalMetrics turns on internal metrics submission. SendInternalMetrics // OmitInternalMetrics turns off internal metrics submission. OmitInternalMetrics )
type ObjectPool ¶
type ObjectPool struct {
// contains filtered or unexported fields
}
ObjectPool is an minimalistic object pool to avoid any circular dependencies on any other object pool.
func (*ObjectPool) Init ¶
func (p *ObjectPool) Init(alloc func() interface{})
Init initializes the object pool.
func (*ObjectPool) Put ¶
func (p *ObjectPool) Put(obj interface{})
Put puts an object back to the pool.
type SanitizeFn ¶
SanitizeFn returns a sanitized version of the input string.
type SanitizeOptions ¶
type SanitizeOptions struct { NameCharacters ValidCharacters KeyCharacters ValidCharacters ValueCharacters ValidCharacters ReplacementCharacter rune }
SanitizeOptions are the set of configurable options for sanitisation.
type SanitizeRange ¶
type SanitizeRange [2]rune
SanitizeRange is a range of characters (inclusive on both ends).
type Sanitizer ¶
type Sanitizer interface { // Name sanitizes the provided `name` string. Name(n string) string // Key sanitizes the provided `key` string. Key(k string) string // Value sanitizes the provided `value` string. Value(v string) string }
Sanitizer sanitizes the provided input based on the function executed.
func NewNoOpSanitizer ¶
func NewNoOpSanitizer() Sanitizer
NewNoOpSanitizer returns a sanitizer which returns all inputs un-touched.
func NewSanitizer ¶
func NewSanitizer(opts SanitizeOptions) Sanitizer
NewSanitizer returns a new sanitizer based on provided options.
type Scope ¶
Scope is a namespace wrapper around a stats reporter, ensuring that all emitted values have a given prefix or set of tags.
IMPORTANT: When using Prometheus reporters, users must take care to
not create metrics from both parent scopes and subscopes that have the same metric name but different tag keys, as metric allocation will panic.
func NewRootScope ¶
NewRootScope creates a new root Scope with a set of options and a reporting interval. Must provide either a StatsReporter or a CachedStatsReporter.
func NewRootScopeWithDefaultInterval ¶
func NewRootScopeWithDefaultInterval(opts ScopeOptions) (Scope, io.Closer)
NewRootScopeWithDefaultInterval invokes NewRootScope with the default reporting interval of 2s.
type ScopeOptions ¶
type ScopeOptions struct { Tags map[string]string Prefix string Reporter StatsReporter CachedReporter CachedStatsReporter Separator string DefaultBuckets Buckets SanitizeOptions *SanitizeOptions MetricsOption InternalMetricOption // contains filtered or unexported fields }
ScopeOptions is a set of options to construct a scope.
type Snapshot ¶
type Snapshot interface { // Counters returns a snapshot of all counter summations since last report execution Counters() map[string]CounterSnapshot // Gauges returns a snapshot of gauge last values since last report execution Gauges() map[string]GaugeSnapshot // Timers returns a snapshot of timer values since last report execution Timers() map[string]TimerSnapshot // Histograms returns a snapshot of histogram samples since last report execution Histograms() map[string]HistogramSnapshot }
Snapshot is a snapshot of values since last report execution
type StatsReporter ¶
type StatsReporter interface { BaseStatsReporter // ReportCounter reports a counter value ReportCounter( name string, tags map[string]string, value int64, ) // ReportGauge reports a gauge value ReportGauge( name string, tags map[string]string, value float64, ) // ReportTimer reports a timer value ReportTimer( name string, tags map[string]string, interval time.Duration, ) // ReportHistogramValueSamples reports histogram samples for a bucket ReportHistogramValueSamples( name string, tags map[string]string, buckets Buckets, bucketLowerBound, bucketUpperBound float64, samples int64, ) // ReportHistogramDurationSamples reports histogram samples for a bucket ReportHistogramDurationSamples( name string, tags map[string]string, buckets Buckets, bucketLowerBound, bucketUpperBound time.Duration, samples int64, ) }
StatsReporter is a backend for Scopes to report metrics to.
var NullStatsReporter StatsReporter = nullStatsReporter{}
NullStatsReporter is an implementation of StatsReporter than simply does nothing.
type Stopwatch ¶
Stopwatch is a helper for simpler tracking of elapsed time, use the Stop() method to report time elapsed since its created back to the timer or histogram.
type StopwatchRecorder ¶
type StopwatchRecorder = ubertally.StopwatchRecorder
StopwatchRecorder is a recorder that is called when a stopwatch is stopped with Stop().
type TestScope ¶
type TestScope interface { Scope // Snapshot returns a copy of all values since the last report execution, // this is an expensive operation and should only be use for testing purposes Snapshot() Snapshot }
TestScope is a metrics collector that has no reporting, ensuring that all emitted values have a given prefix or set of tags
type TimerSnapshot ¶
type TimerSnapshot interface { // Name returns the name Name() string // Tags returns the tags Tags() map[string]string // Values returns the values Values() []time.Duration }
TimerSnapshot is a snapshot of a timer
type ValidCharacters ¶
type ValidCharacters struct { Ranges []SanitizeRange Characters []rune }
ValidCharacters is a collection of valid characters.
type ValueBuckets ¶
type ValueBuckets []float64
ValueBuckets is a set of float64 values that implements Buckets.
func ExponentialValueBuckets ¶
func ExponentialValueBuckets(start, factor float64, n int) (ValueBuckets, error)
ExponentialValueBuckets creates a set of exponential value buckets.
func LinearValueBuckets ¶
func LinearValueBuckets(start, width float64, n int) (ValueBuckets, error)
LinearValueBuckets creates a set of linear value buckets.
func MustMakeExponentialValueBuckets ¶
func MustMakeExponentialValueBuckets(start, factor float64, n int) ValueBuckets
MustMakeExponentialValueBuckets creates a set of exponential value buckets or panics.
func MustMakeLinearValueBuckets ¶
func MustMakeLinearValueBuckets(start, width float64, n int) ValueBuckets
MustMakeLinearValueBuckets creates a set of linear value buckets or panics.
func (ValueBuckets) AsDurations ¶
func (v ValueBuckets) AsDurations() []time.Duration
AsDurations implements Buckets and returns time.Duration representations of the float64 values divided by time.Second.
func (ValueBuckets) AsValues ¶
func (v ValueBuckets) AsValues() []float64
AsValues implements Buckets.
func (ValueBuckets) String ¶
func (v ValueBuckets) String() string