metrics

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EVENTS       = "events"
	TRANSACTIONS = "transactions"
	GAUGES       = "gauges"
)

Variables

This section is empty.

Functions

func Close

func Close()

Close flushes the Client's buffer and releases the associated ressources. The Client and all the cloned Clients must not be used afterward.

func Count

func Count(name string, n interface{}, tags ...map[string]string)

func Flush

func Flush()

Flush flushes the Client's buffer.

func Gauge

func Gauge(name string, value interface{}, tags ...map[string]string)

Gauge records an absolute value for the given name.

func Increment

func Increment(name string, tags ...map[string]string)

Increment increment the given name. It is equivalent to Count(name, 1).

func MeasureTiming

func MeasureTiming(name string, functionToMeasure func(), tags ...map[string]string)

MeasureTiming measures how much time functionToMeasure takes to run.

func Set

func Set(c *Statsd)

func SetFactory

func SetFactory(f func() *Statsd)

func Timing

func Timing(name string, value interface{}, tags ...map[string]string)

Timing sends a timing value to a name.

Types

type ClientFactory

type ClientFactory interface {
	NewClient() *Statsd
}

type Option

type Option = statsd.Option

func Address

func Address(addr string) Option

Address sets the address of the StatsD daemon.

By default, ":8125" is used. This option is ignored in Client.Clone().

func ErrorHandler

func ErrorHandler(h func(error)) Option

ErrorHandler sets the function called when an error happens when sending metrics (e.g. the StatsD daemon is not listening anymore).

By default, these errors are ignored. This option is ignored in Client.Clone().

func FlushPeriod

func FlushPeriod(p time.Duration) Option

FlushPeriod sets how often the Client's buffer is flushed. If p is 0, the goroutine that periodically flush the buffer is not lauched and the buffer is only flushed when it is full.

By default, the flush period is 100 ms. This option is ignored in Client.Clone().

func MaxPacketSize

func MaxPacketSize(n int) Option

MaxPacketSize sets the maximum packet size in bytes sent by the Client.

By default, it is 1440 to avoid IP fragmentation. This option is ignored in Client.Clone().

func Mute

func Mute(b bool) Option

Mute sets whether the Client is muted. All methods of a muted Client do nothing and return immedialtly.

This option can be used in Client.Clone() only if the parent Client is not muted. The clones of a muted Client are always muted.

func Network

func Network(network string) Option

Network sets the network (udp, tcp, etc) used by the client. See the net.Dial documentation (https://golang.org/pkg/net/#Dial) for the available network options.

By default, network is udp. This option is ignored in Client.Clone().

func Prefix

func Prefix(p string) Option

Prefix appends the prefix that will be used in every bucket name.

Note that when used in cloned, the prefix of the parent Client is not replaced but is prepended to the given prefix.

func SampleRate

func SampleRate(rate float32) Option

SampleRate sets the sample rate of the Client. It allows sending the metrics less often which can be useful for performance intensive code paths.

func Tags

func Tags(tags ...string) Option

func TagsFormat

func TagsFormat(tf TagFormat) Option

type Statsd

type Statsd struct {
	Client *statsd.Client
}

Statsd is a wrapper around a statsd client to provide microservice standard support The general usage also hides the need to clone the client for specifying tags. Tags are now received as string hashes, to prevent usage mistakes when using statsd.Tag

func Clone

func Clone(tags ...map[string]string) *Statsd

Clone makes a clone of the Statsd client

func Get

func Get() *Statsd

Get gets the client object created by the client factory.

func NewStatsd

func NewStatsd(address, prefix, version, appName string, sampleRate float32) *Statsd

NewStatsd creates a Statsd object with the given parameters. address is the address of telegraf agent Sample rate sets what percentage of data points would actually be collected. E.g., sampleRate = 1.0 means 100% of the stats are collected; sampleRate = 0.1 means 10% of the stats are collected. 0 < sampleRate <= 1.0

func WithSampleRate

func WithSampleRate(rate float32, tags ...map[string]string) *Statsd

WithSampleRate returns a clone with specified sample rate and tags. Then you can call all the metric functions.

func (*Statsd) Clone

func (s *Statsd) Clone(tags ...map[string]string) *Statsd

Clone clones this Statsd wrapper and its statsd client objects.

func (*Statsd) Close

func (s *Statsd) Close()

Close flushes the Client's buffer and releases the associated ressources. The Client and all the cloned Clients must not be used afterward.

func (*Statsd) Count

func (s *Statsd) Count(name string, value interface{}, tags ...map[string]string)

Count adds n to the EVENTS measurement with the specific name tag

func (*Statsd) Flush

func (s *Statsd) Flush()

Flush flushes the Client's buffer.

func (*Statsd) Gauge

func (s *Statsd) Gauge(name string, value interface{}, tags ...map[string]string)

Gauge records an absolute value for the EVENTS measurement with the specific name tag.

func (*Statsd) Increment

func (s *Statsd) Increment(name string, tags ...map[string]string)

Increment increment the EVENTS measurement with the specific name tag. It is equivalent to Count(name, 1).

func (*Statsd) MeasureTiming

func (s *Statsd) MeasureTiming(name string, functionToMeasure func(), tags ...map[string]string)

MeasureTiming measures and emit metric on the time it takes for functionToMeasure to execute.

func (*Statsd) NewTiming

func (s *Statsd) NewTiming(name string, tags ...map[string]string) *StatsdTiming

NewTiming creates a StatsdTiming object with the current time. Afterwards, the caller will need to call Send() on the StatsdTiming to emit the measurement

func (*Statsd) Timing

func (s *Statsd) Timing(name string, value interface{}, tags ...map[string]string)

Timing sends a timing value to the TRANSACTIONS measurement with the specific name tag.

func (*Statsd) WithSampleRate

func (s *Statsd) WithSampleRate(rate float32, tags ...map[string]string) *Statsd

WithSampleRate returns a clone which will send metrics with the specified sample rate and tags.

type StatsdTiming

type StatsdTiming struct {
	Timing statsd.Timing
}

StatsdTiming when created, it holds a timestamp. When Send() function is called, the timing metric is emitted.

func NewTiming

func NewTiming(name string, tags ...map[string]string) *StatsdTiming

NewTiming returns a StatsdTiming and later you can call Send() on it to finish measuring and emit metric.

func (*StatsdTiming) Send

func (t *StatsdTiming) Send()

Send takes the time difference between now and when the StatsdTiming was created and emit the metrics.

type TagFormat

type TagFormat = statsd.TagFormat

Jump to

Keyboard shortcuts

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