stats

package
v0.0.0-...-b0852c1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, statser Statser) context.Context

NewContext attaches a Statser to a Context

Types

type ChangeGauge

type ChangeGauge struct {
	// Cur is the last value expected to be sent.  If this is changed, SendIfChanged will send the value for
	// 22 flush intervals in an attempt to retry any failures to send it.  Cur is assumed to be atomic by
	// ChangeGauge.SendIfChanged, however if the owner has more specific knowledge, it can be written to
	// with non-atomic operations.
	Cur uint64 // atomic
	// contains filtered or unexported fields
}

ChangeGauge is a simpler wrapper to send a gauge for a rare event, multiple times. It is primarily intended for things that won't change in the majority of cases (such as failure to parse a statsd line), and things that will be bursty (ie, transient http message failure). It isn't suitable for things which are constantly changing such as number of metrics or http requests.

func (*ChangeGauge) SendIfChanged

func (cg *ChangeGauge) SendIfChanged(statser Statser, metricName string, tags gostatsd.Tags)

type ChannelStatsWatcher

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

ChannelStatsWatcher reports metrics about channel usage to a Statser

func NewChannelStatsWatcher

func NewChannelStatsWatcher(statser Statser, channelName string, tags gostatsd.Tags, capacity int, lenFunc func() int, sampleInterval time.Duration) *ChannelStatsWatcher

NewChannelStatsWatcher creates a new ChannelStatsWatcher

func (*ChannelStatsWatcher) Run

func (csw *ChannelStatsWatcher) Run(ctx context.Context)

Run will run a ChannelStatsWatcher in the background until the supplied context is closed. Metrics are sampled every sampleInterval, and written every flush.

type HeartBeater

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

HeartBeater periodically sends a gauge for heartbeat purposes

func NewHeartBeater

func NewHeartBeater(metricName string, tags gostatsd.Tags) *HeartBeater

NewHeartBeater creates a new HeartBeater

func (*HeartBeater) Run

func (hb *HeartBeater) Run(ctx context.Context)

Run will run a HeartBeater in the background until the supplied context is closed.

type InternalStatser

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

InternalStatser is a Statser which sends metrics to a handler on a best effort basis. If all buffers are full, metrics will be dropped. Dropped metrics will be accumulated and emitted as a gauge (not counter). Metrics sent after the context is closed will be counted as dropped, but never surfaced because it has nowhere to submit them.

There is an assumption (but not enforcement) that InternalStatser is a singleton, and therefore there is no namespacing/tags on the dropped metrics.

func NewInternalStatser

func NewInternalStatser(
	tags gostatsd.Tags,
	namespace string,
	hostname gostatsd.Source,
	handler gostatsd.PipelineHandler,
	disableEvents bool,
	forwarderMode bool,
) *InternalStatser

NewInternalStatser creates a new Statser which sends metrics to the supplied InternalHandler.

func (*InternalStatser) Count

func (is *InternalStatser) Count(name string, amount float64, tags gostatsd.Tags)

Count sends a counter metric

func (*InternalStatser) Event

func (is *InternalStatser) Event(ctx context.Context, e *gostatsd.Event)

func (*InternalStatser) Gauge

func (is *InternalStatser) Gauge(name string, value float64, tags gostatsd.Tags)

Gauge sends a gauge metric

func (*InternalStatser) Increment

func (is *InternalStatser) Increment(name string, tags gostatsd.Tags)

Increment sends a counter metric with a value of 1

func (*InternalStatser) NewTimer

func (is *InternalStatser) NewTimer(name string, tags gostatsd.Tags) *Timer

NewTimer returns a new timer with time set to now

func (*InternalStatser) NotifyFlush

func (is *InternalStatser) NotifyFlush(ctx context.Context, d time.Duration)

func (*InternalStatser) RegisterFlush

func (fn *InternalStatser) RegisterFlush() (ch <-chan time.Duration, unregister func())

RegisterFlush returns a channel which will receive a notification after every flush, and a cleanup function which should be called to signal the channel is no longer being monitored. If the channel blocks, the notification will be silently dropped. Thread-safe.

func (*InternalStatser) Report

func (is *InternalStatser) Report(name string, value *uint64, tags gostatsd.Tags)

func (*InternalStatser) TimingDuration

func (is *InternalStatser) TimingDuration(name string, d time.Duration, tags gostatsd.Tags)

TimingDuration sends a timing metric from a time.Duration

func (*InternalStatser) TimingMS

func (is *InternalStatser) TimingMS(name string, ms float64, tags gostatsd.Tags)

TimingMS sends a timing metric from a millisecond value

func (*InternalStatser) WaitForEvents

func (is *InternalStatser) WaitForEvents()

func (*InternalStatser) WithTags

func (is *InternalStatser) WithTags(tags gostatsd.Tags) Statser

WithTags creates a new Statser with additional tags

type LoggingStatser

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

LoggingStatser is a Statser which emits logs

func (*LoggingStatser) Count

func (ls *LoggingStatser) Count(name string, amount float64, tags gostatsd.Tags)

Count sends a counter metric

func (*LoggingStatser) Event

func (ls *LoggingStatser) Event(ctx context.Context, e *gostatsd.Event)

func (*LoggingStatser) Gauge

func (ls *LoggingStatser) Gauge(name string, value float64, tags gostatsd.Tags)

Gauge sends a gauge metric

func (*LoggingStatser) Increment

func (ls *LoggingStatser) Increment(name string, tags gostatsd.Tags)

Increment sends a counter metric with a value of 1

func (*LoggingStatser) NewTimer

func (ls *LoggingStatser) NewTimer(name string, tags gostatsd.Tags) *Timer

NewTimer returns a new timer with time set to now

func (*LoggingStatser) NotifyFlush

func (fn *LoggingStatser) NotifyFlush(ctx context.Context, d time.Duration)

NotifyFlush will notify any registered channels that a flush has completed. Non-blocking, thread-safe.

func (*LoggingStatser) RegisterFlush

func (fn *LoggingStatser) RegisterFlush() (ch <-chan time.Duration, unregister func())

RegisterFlush returns a channel which will receive a notification after every flush, and a cleanup function which should be called to signal the channel is no longer being monitored. If the channel blocks, the notification will be silently dropped. Thread-safe.

func (*LoggingStatser) Report

func (ls *LoggingStatser) Report(name string, value *uint64, tags gostatsd.Tags)

func (*LoggingStatser) TimingDuration

func (ls *LoggingStatser) TimingDuration(name string, d time.Duration, tags gostatsd.Tags)

TimingDuration sends a timing metric from a time.Duration

func (*LoggingStatser) TimingMS

func (ls *LoggingStatser) TimingMS(name string, ms float64, tags gostatsd.Tags)

TimingMS sends a timing metric from a millisecond value

func (*LoggingStatser) WaitForEvents

func (ls *LoggingStatser) WaitForEvents()

func (*LoggingStatser) WithTags

func (ls *LoggingStatser) WithTags(tags gostatsd.Tags) Statser

WithTags creates a new Statser with additional tags

type NullStatser

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

NullStatser is a null implementation of Statser, intended primarily for test purposes

func (*NullStatser) Count

func (ns *NullStatser) Count(name string, amount float64, tags gostatsd.Tags)

Count does nothing

func (*NullStatser) Event

func (ns *NullStatser) Event(ctx context.Context, e *gostatsd.Event)

func (*NullStatser) Gauge

func (ns *NullStatser) Gauge(name string, value float64, tags gostatsd.Tags)

Gauge does nothing

func (*NullStatser) Increment

func (ns *NullStatser) Increment(name string, tags gostatsd.Tags)

Increment does nothing

func (*NullStatser) NewTimer

func (ns *NullStatser) NewTimer(name string, tags gostatsd.Tags) *Timer

NewTimer returns a new timer with time set to now

func (*NullStatser) NotifyFlush

func (fn *NullStatser) NotifyFlush(ctx context.Context, d time.Duration)

NotifyFlush will notify any registered channels that a flush has completed. Non-blocking, thread-safe.

func (*NullStatser) RegisterFlush

func (fn *NullStatser) RegisterFlush() (ch <-chan time.Duration, unregister func())

RegisterFlush returns a channel which will receive a notification after every flush, and a cleanup function which should be called to signal the channel is no longer being monitored. If the channel blocks, the notification will be silently dropped. Thread-safe.

func (*NullStatser) Report

func (ns *NullStatser) Report(name string, value *uint64, tags gostatsd.Tags)

func (*NullStatser) TimingDuration

func (ns *NullStatser) TimingDuration(name string, d time.Duration, tags gostatsd.Tags)

TimingDuration does nothing

func (*NullStatser) TimingMS

func (ns *NullStatser) TimingMS(name string, ms float64, tags gostatsd.Tags)

TimingMS does nothing

func (*NullStatser) WaitForEvents

func (ns *NullStatser) WaitForEvents()

func (*NullStatser) WithTags

func (ns *NullStatser) WithTags(tags gostatsd.Tags) Statser

WithTags returns a NullStatser

type Statser

type Statser interface {
	// NotifyFlush is called when a flush occurs.  It signals all known subscribers.
	NotifyFlush(ctx context.Context, d time.Duration)
	// RegisterFlush returns a channel which will receive a notification after every flush, and a cleanup
	// function which should be called to signal the channel is no longer being monitored.  If the channel
	// blocks, the notification will be silently dropped.
	RegisterFlush() (ch <-chan time.Duration, unregister func())

	Gauge(name string, value float64, tags gostatsd.Tags)
	Count(name string, amount float64, tags gostatsd.Tags)
	Increment(name string, tags gostatsd.Tags)
	Report(name string, value *uint64, tags gostatsd.Tags)
	TimingMS(name string, ms float64, tags gostatsd.Tags)
	TimingDuration(name string, d time.Duration, tags gostatsd.Tags)
	NewTimer(name string, tags gostatsd.Tags) *Timer
	WithTags(tags gostatsd.Tags) Statser

	Event(ctx context.Context, e *gostatsd.Event)
	WaitForEvents()
}

Statser is the interface for sending metrics

func FromContext

func FromContext(ctx context.Context) Statser

FromContext returns a Statser from a Context. Always succeeds, will return a NullStatser if there is no statser present.

func NewLoggingStatser

func NewLoggingStatser(tags gostatsd.Tags, logger logrus.FieldLogger) Statser

NewLoggingStatser creates a new Statser which sends metrics to the supplied logger.

func NewNullStatser

func NewNullStatser() Statser

NewNullStatser creates a new NullStatser

func NewTaggedStatser

func NewTaggedStatser(statser Statser, tags gostatsd.Tags) Statser

NewTaggedStatser creates a new Statser which adds additional tags all metrics submitted.

type TaggedStatser

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

TaggedStatser adds tags and submits metrics to another Statser

func (*TaggedStatser) Count

func (ts *TaggedStatser) Count(name string, amount float64, tags gostatsd.Tags)

Count sends a counter metric

func (*TaggedStatser) Event

func (ts *TaggedStatser) Event(ctx context.Context, e *gostatsd.Event)

func (*TaggedStatser) Gauge

func (ts *TaggedStatser) Gauge(name string, value float64, tags gostatsd.Tags)

Gauge sends a gauge metric

func (*TaggedStatser) Increment

func (ts *TaggedStatser) Increment(name string, tags gostatsd.Tags)

Increment sends a counter metric with a value of 1

func (*TaggedStatser) NewTimer

func (ts *TaggedStatser) NewTimer(name string, tags gostatsd.Tags) *Timer

NewTimer returns a new timer with time set to now

func (*TaggedStatser) NotifyFlush

func (ts *TaggedStatser) NotifyFlush(ctx context.Context, d time.Duration)

func (*TaggedStatser) RegisterFlush

func (ts *TaggedStatser) RegisterFlush() (<-chan time.Duration, func())

func (*TaggedStatser) Report

func (ts *TaggedStatser) Report(name string, value *uint64, tags gostatsd.Tags)

func (*TaggedStatser) TimingDuration

func (ts *TaggedStatser) TimingDuration(name string, d time.Duration, tags gostatsd.Tags)

TimingDuration sends a timing metric from a time.Duration

func (*TaggedStatser) TimingMS

func (ts *TaggedStatser) TimingMS(name string, ms float64, tags gostatsd.Tags)

TimingMS sends a timing metric from a millisecond value

func (*TaggedStatser) WaitForEvents

func (ts *TaggedStatser) WaitForEvents()

func (*TaggedStatser) WithTags

func (ts *TaggedStatser) WithTags(tags gostatsd.Tags) Statser

WithTags creates a new Statser with additional tags

type Timer

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

Timer times an operation and submits a timing or gauge metric

func (*Timer) Send

func (t *Timer) Send()

Send sends a timing style metric

func (*Timer) SendGauge

func (t *Timer) SendGauge()

SendGauge sends a gauge metric in milliseconds

func (*Timer) Stop

func (t *Timer) Stop()

Stop stops the time being recorded

Jump to

Keyboard shortcuts

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