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 = "3.5.5"
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 = "."
)
Functions ¶
func KeyForPrefixedStringMap ¶ added in v1.1.0
KeyForPrefixedStringMap generates a unique key for a a prefix and a map string set combination.
func KeyForStringMap ¶ added in v1.1.0
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 interface { LowerBoundValue() float64 UpperBoundValue() float64 LowerBoundDuration() time.Duration UpperBoundDuration() time.Duration }
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 ¶
type Buckets interface { fmt.Stringer sort.Interface // AsValues returns a representation of the buckets as float64s AsValues() []float64 // AsDurations returns a representation of the buckets as time.Durations AsDurations() []time.Duration }
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 interface { // Reporting returns whether the reporter has the ability to actively report. Reporting() bool // Tagging returns whether the reporter has the capability for tagged metrics. Tagging() bool }
Capabilities is a description of metrics reporting capabilities.
type Counter ¶
type Counter interface { // Inc increments the counter by a delta. Inc(delta int64) }
Counter is the interface for emitting counter type metrics.
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 Gauge ¶
type Gauge interface { // Update sets the gauges absolute value. Update(value float64) }
Gauge is the interface for emitting gauge metrics.
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 Histogram ¶
type Histogram interface { // RecordValue records a specific value directly. // Will use the configured value buckets for the histogram. RecordValue(value float64) // RecordDuration records a specific duration directly. // Will use the configured duration buckets for the histogram. RecordDuration(value time.Duration) // Start gives you a specific point in time to then record a duration. // Will use the configured duration buckets for the histogram. Start() Stopwatch }
Histogram is the interface for emitting histogram metrics
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 ¶ added in v1.1.0
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 NewObjectPool ¶ added in v1.1.0
func NewObjectPool(size int) *ObjectPool
NewObjectPool creates a new pool.
func (*ObjectPool) Get ¶ added in v1.1.0
func (p *ObjectPool) Get() interface{}
Get gets an object from the pool.
func (*ObjectPool) Init ¶ added in v1.1.0
func (p *ObjectPool) Init(alloc func() interface{})
Init initializes the object pool.
func (*ObjectPool) Put ¶ added in v1.1.0
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 ¶
type Scope interface { // Counter returns the Counter object corresponding to the name. Counter(name string) Counter // Gauge returns the Gauge object corresponding to the name. Gauge(name string) Gauge // Timer returns the Timer object corresponding to the name. Timer(name string) Timer // Histogram returns the Histogram object corresponding to the name. // To use default value and duration buckets configured for the scope // simply pass tally.DefaultBuckets or nil. // You can use tally.ValueBuckets{x, y, ...} for value buckets. // You can use tally.DurationBuckets{x, y, ...} for duration buckets. // You can use tally.MustMakeLinearValueBuckets(start, width, count) for linear values. // You can use tally.MustMakeLinearDurationBuckets(start, width, count) for linear durations. // You can use tally.MustMakeExponentialValueBuckets(start, factor, count) for exponential values. // You can use tally.MustMakeExponentialDurationBuckets(start, factor, count) for exponential durations. Histogram(name string, buckets Buckets) Histogram // Tagged returns a new child scope with the given tags and current tags. Tagged(tags map[string]string) Scope // SubScope returns a new child scope appending a further name prefix. SubScope(name string) Scope // Capabilities returns a description of metrics reporting capabilities. Capabilities() Capabilities }
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.
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 ¶
type Stopwatch struct {
// contains filtered or unexported fields
}
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.
func NewStopwatch ¶
func NewStopwatch(start time.Time, r StopwatchRecorder) Stopwatch
NewStopwatch creates a new immutable stopwatch for recording the start time to a stopwatch reporter.
type 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 Timer ¶
type Timer interface { // Record a specific duration directly. Record(value time.Duration) // Start gives you back a specific point in time to report via Stop. Start() Stopwatch }
Timer is the interface for emitting timer metrics.
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