stats

package
v4.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHeartbeatInterval = time.Second

DefaultHeartbeatInterval is the default heartbeat ticker interval.

View Source
var DefaultRuntimeInterval = 30 * time.Second

DefaultRuntimeInterval is the default runtime ticker interval.

View Source
var (
	// Null is the null Stats instance.
	Null = &nullStats{}
)

Functions

func Close

func Close(ctx context.Context) error

Close closes the client and flushes buffered stats, if applicable

func Dec

func Dec(ctx context.Context, name string, value int64, rate float32, tags ...interface{}) error

Dec decrements a count by the value.

func Gauge

func Gauge(ctx context.Context, name string, value float64, rate float32, tags ...interface{}) error

Gauge measures the value of a metric.

func Heartbeat

func Heartbeat(stats Stats)

Heartbeat enters a loop, reporting a heartbeat counter periodically.

func HeartbeatEvery

func HeartbeatEvery(stats Stats, t time.Duration)

HeartbeatEvery enters a loop, reporting a heartbeat counter at the specified interval.

func HeartbeatFromContext

func HeartbeatFromContext(ctx context.Context, t time.Duration)

HeartbeatFromContext is the same as HeartbeatEvery but from context.

func Inc

func Inc(ctx context.Context, name string, value int64, rate float32, tags ...interface{}) error

Inc increments a count by the value.

func Runtime

func Runtime(stats Stats)

Runtime enters a loop, reporting runtime stats periodically.

func RuntimeEvery

func RuntimeEvery(stats Stats, t time.Duration)

RuntimeEvery enters a loop, reporting runtime stats at the specified interval.

func RuntimeFromContext

func RuntimeFromContext(ctx context.Context, t time.Duration)

RuntimeFromContext is the same as RuntimeEvery but from context.

func Timing

func Timing(ctx context.Context, name string, value time.Duration, rate float32, tags ...interface{}) error

Timing sends the value of a Duration.

func WithStats

func WithStats(ctx context.Context, stats Stats) context.Context

WithStats sets Stats in the context.

Types

type BufferedStatsd

type BufferedStatsd struct {
	// contains filtered or unexported fields
}

BufferedStatsd represents a buffered statsd client.

func NewBufferedStatsd

func NewBufferedStatsd(addr, prefix string, opts ...BufferedStatsdFunc) (*BufferedStatsd, error)

NewBufferedStatsd create a buffered Statsd instance.

func (*BufferedStatsd) Close

func (s *BufferedStatsd) Close() error

Close closes the client and flushes buffered stats, if applicable

func (*BufferedStatsd) Dec

func (s *BufferedStatsd) Dec(name string, value int64, rate float32, tags ...interface{}) error

Dec decrements a count by the value.

func (*BufferedStatsd) Gauge

func (s *BufferedStatsd) Gauge(name string, value float64, rate float32, tags ...interface{}) error

Gauge measures the value of a metric.

func (*BufferedStatsd) Inc

func (s *BufferedStatsd) Inc(name string, value int64, rate float32, tags ...interface{}) error

Inc increments a count by the value.

func (*BufferedStatsd) Timing

func (s *BufferedStatsd) Timing(name string, value time.Duration, rate float32, tags ...interface{}) error

Timing sends the value of a Duration.

type BufferedStatsdFunc

type BufferedStatsdFunc func(*BufferedStatsd)

BufferedStatsdFunc represents an configuration function for BufferedStatsd.

func WithFlushBytes

func WithFlushBytes(bytes int) BufferedStatsdFunc

WithFlushBytes sets the maximum udp packet size that will be sent. Defaults to 1432 flushBytes.

func WithFlushInterval

func WithFlushInterval(interval time.Duration) BufferedStatsdFunc

WithFlushInterval sets the maximum flushInterval for packet sending. Defaults to 300ms.

type L2met

type L2met struct {
	// contains filtered or unexported fields
}

L2met represents a l2met client.

func (*L2met) Close

func (s *L2met) Close() error

Close closes the client and flushes buffered stats, if applicable

func (*L2met) Dec

func (s *L2met) Dec(name string, value int64, rate float32, tags ...interface{}) error

Dec decrements a count by the value.

func (*L2met) Gauge

func (s *L2met) Gauge(name string, value float64, rate float32, tags ...interface{}) error

Gauge measures the value of a metric.

func (*L2met) Inc

func (s *L2met) Inc(name string, value int64, rate float32, tags ...interface{}) error

Inc increments a count by the value.

func (*L2met) Timing

func (s *L2met) Timing(name string, value time.Duration, rate float32, tags ...interface{}) error

Timing sends the value of a Duration.

type L2metFunc

type L2metFunc func(*L2met)

L2metFunc represents a function that configures L2met.

func UseRates

func UseRates() L2metFunc

UseRates turns on sample rates in l2met.

func UseSampler

func UseSampler(sampler SamplerFunc) L2metFunc

UseSampler sets the sampler for l2met.

type Prometheus

type Prometheus struct {
	// contains filtered or unexported fields
}

Prometheus represents a promethus stats collector.

func NewPrometheus

func NewPrometheus(prefix string) *Prometheus

NewPrometheus creates a new Prometheus stats instance.

func (*Prometheus) Close

func (s *Prometheus) Close() error

Close closes the client and flushes buffered stats, if applicable

func (*Prometheus) Dec

func (s *Prometheus) Dec(name string, value int64, rate float32, tags ...interface{}) error

Dec decrements a count by the value.

func (*Prometheus) Gauge

func (s *Prometheus) Gauge(name string, value float64, rate float32, tags ...interface{}) error

Gauge measures the value of a metric.

func (*Prometheus) Handler

func (s *Prometheus) Handler() http.Handler

Handler gets the prometheus HTTP handler.

func (*Prometheus) Inc

func (s *Prometheus) Inc(name string, value int64, rate float32, tags ...interface{}) error

Inc increments a count by the value.

func (*Prometheus) Timing

func (s *Prometheus) Timing(name string, value time.Duration, rate float32, tags ...interface{}) error

Timing sends the value of a Duration.

type SamplerFunc

type SamplerFunc func(float32) bool

SamplerFunc represents a function that samples the L2met stats.

type Stats

type Stats interface {
	io.Closer

	// Inc increments a count by the value.
	Inc(name string, value int64, rate float32, tags ...interface{}) error

	// Dec decrements a count by the value.
	Dec(name string, value int64, rate float32, tags ...interface{}) error

	// Gauge measures the value of a metric.
	Gauge(name string, value float64, rate float32, tags ...interface{}) error

	// Timing sends the value of a Duration.
	Timing(name string, value time.Duration, rate float32, tags ...interface{}) error
}

Stats represents a stats instance.

func FromContext

func FromContext(ctx context.Context) (Stats, bool)

FromContext returns the instance of Stats in the context.

func NewL2met

func NewL2met(l log.Logger, prefix string, opts ...L2metFunc) Stats

NewL2met create a l2met instance.

func NewStatsd

func NewStatsd(addr, prefix string) (Stats, error)

NewStatsd create a Statsd instance.

type Statsd

type Statsd struct {
	// contains filtered or unexported fields
}

Statsd represents a statsd client.

func (*Statsd) Close

func (s *Statsd) Close() error

Close closes the client and flushes buffered stats, if applicable

func (*Statsd) Dec

func (s *Statsd) Dec(name string, value int64, rate float32, tags ...interface{}) error

Dec decrements a count by the value.

func (*Statsd) Gauge

func (s *Statsd) Gauge(name string, value float64, rate float32, tags ...interface{}) error

Gauge measures the value of a metric.

func (*Statsd) Inc

func (s *Statsd) Inc(name string, value int64, rate float32, tags ...interface{}) error

Inc increments a count by the value.

func (*Statsd) Timing

func (s *Statsd) Timing(name string, value time.Duration, rate float32, tags ...interface{}) error

Timing sends the value of a Duration.

type TaggedStats

type TaggedStats struct {
	// contains filtered or unexported fields
}

TaggedStats wraps a Stats instance applying tags to all metrics.

func NewTaggedStats

func NewTaggedStats(stats Stats, tags ...interface{}) *TaggedStats

NewTaggedStats creates a new TaggedStats instance.

func (TaggedStats) Close

func (s TaggedStats) Close() error

Close closes the client and flushes buffered stats, if applicable

func (TaggedStats) Dec

func (s TaggedStats) Dec(name string, value int64, rate float32, tags ...interface{}) error

Dec decrements a count by the value.

func (TaggedStats) Gauge

func (s TaggedStats) Gauge(name string, value float64, rate float32, tags ...interface{}) error

Gauge measures the value of a metric.

func (TaggedStats) Inc

func (s TaggedStats) Inc(name string, value int64, rate float32, tags ...interface{}) error

Inc increments a count by the value.

func (TaggedStats) Timing

func (s TaggedStats) Timing(name string, value time.Duration, rate float32, tags ...interface{}) error

Timing sends the value of a Duration.

type Tags

type Tags map[string]string

Tags is a map of strings that adds some convenience functionality over the vanilla go map. Deprecated. Warning! There is a known bug where Tags passed to any stats func (like Inc, Gauge, etc.) will not be merge correctly into the global tags. This might result in the stats loss! Do not pass Tags object to those functions, use the variadic list instead..

func (Tags) Merge

func (t Tags) Merge(t2 Tags) Tags

Merge adds the values from t2 to t, overriding the conflicting keys.

func (Tags) With

func (t Tags) With(key, value string) Tags

With adds the value to the key.

type Timer

type Timer interface {
	// Start starts the timer.
	Start()
	// Done stops the timer and submits the Timing metric.
	Done()
}

Timer represents a timer.

func Time

func Time(ctx context.Context, name string, rate float32, tags ...interface{}) Timer

Time is a shorthand for Timing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL