Documentation ¶
Index ¶
- Constants
- func Close()
- func Count(name string, n interface{}, tags ...map[string]string)
- func Flush()
- func Gauge(name string, value interface{}, tags ...map[string]string)
- func Increment(name string, tags ...map[string]string)
- func MeasureTiming(name string, functionToMeasure func(), tags ...map[string]string)
- func Set(c *Statsd)
- func SetFactory(f func() *Statsd)
- func Timing(name string, value interface{}, tags ...map[string]string)
- type ClientFactory
- type Option
- func Address(addr string) Option
- func ErrorHandler(h func(error)) Option
- func FlushPeriod(p time.Duration) Option
- func MaxPacketSize(n int) Option
- func Mute(b bool) Option
- func Network(network string) Option
- func Prefix(p string) Option
- func SampleRate(rate float32) Option
- func Tags(tags ...string) Option
- func TagsFormat(tf TagFormat) Option
- type Statsd
- func (s *Statsd) Clone(tags ...map[string]string) *Statsd
- func (s *Statsd) Close()
- func (s *Statsd) Count(name string, value interface{}, tags ...map[string]string)
- func (s *Statsd) Flush()
- func (s *Statsd) Gauge(name string, value interface{}, tags ...map[string]string)
- func (s *Statsd) Increment(name string, tags ...map[string]string)
- func (s *Statsd) MeasureTiming(name string, functionToMeasure func(), tags ...map[string]string)
- func (s *Statsd) NewTiming(name string, tags ...map[string]string) *StatsdTiming
- func (s *Statsd) Timing(name string, value interface{}, tags ...map[string]string)
- func (s *Statsd) WithSampleRate(rate float32, tags ...map[string]string) *Statsd
- type StatsdTiming
- type TagFormat
Constants ¶
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 MeasureTiming ¶
MeasureTiming measures how much time functionToMeasure takes to run.
func SetFactory ¶
func SetFactory(f func() *Statsd)
Types ¶
type ClientFactory ¶
type ClientFactory interface {
NewClient() *Statsd
}
type Option ¶
type Option = statsd.Option
func Address ¶
Address sets the address of the StatsD daemon.
By default, ":8125" is used. This option is ignored in Client.Clone().
func ErrorHandler ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 TagsFormat ¶
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 NewStatsd ¶
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 ¶
WithSampleRate returns a clone with specified sample rate and tags. Then you can call all the metric functions.
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) Gauge ¶
Gauge records an absolute value for the EVENTS measurement with the specific name tag.
func (*Statsd) Increment ¶
Increment increment the EVENTS measurement with the specific name tag. It is equivalent to Count(name, 1).
func (*Statsd) MeasureTiming ¶
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
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.