tally: github.com/uber-go/tally Index | Files | Directories

package tally

import "github.com/uber-go/tally"

Index

Package Files

histogram.go key_gen.go pool.go reporter.go sanitize.go scope.go stats.go types.go

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 = "."
)

func KeyForPrefixedStringMap Uses

func KeyForPrefixedStringMap(
    prefix string,
    stringMap map[string]string,
) string

KeyForPrefixedStringMap generates a unique key for a a prefix and a map string set combination.

func KeyForStringMap Uses

func KeyForStringMap(
    stringMap map[string]string,
) string

KeyForStringMap generates a unique key for a map string set combination.

func NoOpSanitizeFn Uses

func NoOpSanitizeFn(v string) string

NoOpSanitizeFn returns the input un-touched.

type BaseStatsReporter Uses

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 Uses

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 Uses

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 Uses

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 Uses

type CachedCount interface {
    ReportCount(value int64)
}

CachedCount interface for reporting an individual counter

type CachedGauge Uses

type CachedGauge interface {
    ReportGauge(value float64)
}

CachedGauge interface for reporting an individual gauge

type CachedHistogram Uses

type CachedHistogram interface {
    ValueBucket(
        bucketLowerBound, bucketUpperBound float64,
    ) CachedHistogramBucket
    DurationBucket(
        bucketLowerBound, bucketUpperBound time.Duration,
    ) CachedHistogramBucket
}

CachedHistogram interface for reporting histogram samples to buckets

type CachedHistogramBucket Uses

type CachedHistogramBucket interface {
    ReportSamples(value int64)
}

CachedHistogramBucket interface for reporting histogram samples to a specific bucket

type CachedStatsReporter Uses

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 Uses

type CachedTimer interface {
    ReportTimer(interval time.Duration)
}

CachedTimer interface for reporting an individual timer

type Capabilities Uses

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 Uses

type Counter interface {
    // Inc increments the counter by a delta.
    Inc(delta int64)
}

Counter is the interface for emitting counter type metrics.

type CounterSnapshot Uses

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 Uses

type DurationBuckets []time.Duration

DurationBuckets is a set of time.Duration values that implements Buckets.

func ExponentialDurationBuckets Uses

func ExponentialDurationBuckets(start time.Duration, factor float64, n int) (DurationBuckets, error)

ExponentialDurationBuckets creates a set of exponential duration buckets.

func LinearDurationBuckets Uses

func LinearDurationBuckets(start, width time.Duration, n int) (DurationBuckets, error)

LinearDurationBuckets creates a set of linear duration buckets.

func MustMakeExponentialDurationBuckets Uses

func MustMakeExponentialDurationBuckets(start time.Duration, factor float64, n int) DurationBuckets

MustMakeExponentialDurationBuckets creates a set of exponential value buckets or panics.

func MustMakeLinearDurationBuckets Uses

func MustMakeLinearDurationBuckets(start, width time.Duration, n int) DurationBuckets

MustMakeLinearDurationBuckets creates a set of linear duration buckets. or panics.

func (DurationBuckets) AsDurations Uses

func (v DurationBuckets) AsDurations() []time.Duration

AsDurations implements Buckets.

func (DurationBuckets) AsValues Uses

func (v DurationBuckets) AsValues() []float64

AsValues implements Buckets and returns float64 representations of the time.Duration values divided by time.Second.

func (DurationBuckets) Len Uses

func (v DurationBuckets) Len() int

Implements sort.Interface

func (DurationBuckets) Less Uses

func (v DurationBuckets) Less(i, j int) bool

Implements sort.Interface

func (DurationBuckets) String Uses

func (v DurationBuckets) String() string

func (DurationBuckets) Swap Uses

func (v DurationBuckets) Swap(i, j int)

Implements sort.Interface

type Gauge Uses

type Gauge interface {
    // Update sets the gauges absolute value.
    Update(value float64)
}

Gauge is the interface for emitting gauge metrics.

type GaugeSnapshot Uses

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 Uses

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 Uses

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 ObjectPool Uses

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 Uses

func NewObjectPool(size int) *ObjectPool

NewObjectPool creates a new pool.

func (*ObjectPool) Get Uses

func (p *ObjectPool) Get() interface{}

Get gets an object from the pool.

func (*ObjectPool) Init Uses

func (p *ObjectPool) Init(alloc func() interface{})

Init initializes the object pool.

func (*ObjectPool) Put Uses

func (p *ObjectPool) Put(obj interface{})

Put puts an object back to the pool.

type SanitizeFn Uses

type SanitizeFn func(string) string

SanitizeFn returns a sanitized version of the input string.

type SanitizeOptions Uses

type SanitizeOptions struct {
    NameCharacters       ValidCharacters
    KeyCharacters        ValidCharacters
    ValueCharacters      ValidCharacters
    ReplacementCharacter rune
}

SanitizeOptions are the set of configurable options for sanitisation.

type SanitizeRange Uses

type SanitizeRange [2]rune

SanitizeRange is a range of characters (inclusive on both ends).

type Sanitizer Uses

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 Uses

func NewNoOpSanitizer() Sanitizer

NewNoOpSanitizer returns a sanitizer which returns all inputs un-touched.

func NewSanitizer Uses

func NewSanitizer(opts SanitizeOptions) Sanitizer

NewSanitizer returns a new sanitizer based on provided options.

type Scope Uses

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 Uses

func NewRootScope(opts ScopeOptions, interval time.Duration) (Scope, io.Closer)

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 Uses

type ScopeOptions struct {
    Tags            map[string]string
    Prefix          string
    Reporter        StatsReporter
    CachedReporter  CachedStatsReporter
    Separator       string
    DefaultBuckets  Buckets
    SanitizeOptions *SanitizeOptions
}

ScopeOptions is a set of options to construct a scope.

type Snapshot Uses

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 Uses

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 Uses

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 Uses

func NewStopwatch(start time.Time, r StopwatchRecorder) Stopwatch

NewStopwatch creates a new immutable stopwatch for recording the start time to a stopwatch reporter.

func (Stopwatch) Stop Uses

func (sw Stopwatch) Stop()

Stop reports time elapsed since the stopwatch start to the recorder.

type StopwatchRecorder Uses

type StopwatchRecorder interface {
    RecordStopwatch(stopwatchStart time.Time)
}

StopwatchRecorder is a recorder that is called when a stopwatch is stopped with Stop().

type TestScope Uses

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

func NewTestScope Uses

func NewTestScope(
    prefix string,
    tags map[string]string,
) TestScope

NewTestScope creates a new Scope without a stats reporter with the given prefix and adds the ability to take snapshots of metrics emitted to it.

type Timer Uses

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 Uses

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 Uses

type ValidCharacters struct {
    Ranges     []SanitizeRange
    Characters []rune
}

ValidCharacters is a collection of valid characters.

type ValueBuckets Uses

type ValueBuckets []float64

ValueBuckets is a set of float64 values that implements Buckets.

func ExponentialValueBuckets Uses

func ExponentialValueBuckets(start, factor float64, n int) (ValueBuckets, error)

ExponentialValueBuckets creates a set of exponential value buckets.

func LinearValueBuckets Uses

func LinearValueBuckets(start, width float64, n int) (ValueBuckets, error)

LinearValueBuckets creates a set of linear value buckets.

func MustMakeExponentialValueBuckets Uses

func MustMakeExponentialValueBuckets(start, factor float64, n int) ValueBuckets

MustMakeExponentialValueBuckets creates a set of exponential value buckets or panics.

func MustMakeLinearValueBuckets Uses

func MustMakeLinearValueBuckets(start, width float64, n int) ValueBuckets

MustMakeLinearValueBuckets creates a set of linear value buckets or panics.

func (ValueBuckets) AsDurations Uses

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 Uses

func (v ValueBuckets) AsValues() []float64

AsValues implements Buckets.

func (ValueBuckets) Len Uses

func (v ValueBuckets) Len() int

Implements sort.Interface

func (ValueBuckets) Less Uses

func (v ValueBuckets) Less(i, j int) bool

Implements sort.Interface

func (ValueBuckets) String Uses

func (v ValueBuckets) String() string

func (ValueBuckets) Swap Uses

func (v ValueBuckets) Swap(i, j int)

Implements sort.Interface

Directories

PathSynopsis
example
instrument
m3
m3/customtransports
m3/example
m3/thrift
m3/thriftudp
multi
prometheus
prometheus/example
statsd
statsd/example
thirdparty/github.com/apache/thrift/lib/go/thrift

Package tally imports 9 packages (graph) and is imported by 283 packages. Updated 2019-11-08. Refresh now. Tools for package owners.