statsd

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: MIT Imports: 8 Imported by: 3

README

go-statsd-client

Client for StatsD (Golang)

Go Report Card GoDoc Build Status Code Climate

Installation

go get -u github.com/GoMetric/go-statsd-client

Usage

Client may be in buffered and unbuffered mode.

In buffered mode adding metric only adds it to buffer. Then client.Flush() builds all metrics to packed and sends them to StatsD server by one request.

In unbuffered mode each metric sends to StatsD immediately.

Creating unbuffered client:

client := NewClient("127.0.0.1", 9876)  # create client
client.Open()                           # open connection to StatsD
client.Count("a.b.c", 42, 0.7)          # set count metric and send it to StatsD

Creating buffered client:

client := NewBufferedClient("127.0.0.1", 9876) # create client
client.Open()                                  # open connection to StatsD
client.Count("a.b.c", 42, 0.7)                 # set count metric and add it to buffer
client.Timing("a.b.d", 43)                     # set timing metric and add it to buffer
client.Flush()                                 # send all metrics as one packet to StatsD

Add metric prefix to all keys:

client := NewBufferedClient("127.0.0.1", 9876) # create client
client.SetPrefix("prefix")                     # set prefix to all keys
client.Open()                                  # open connection to StatsD
client.Count("a.b.c", 42, 0.7)                 # set count metric "prefix.a.b.c" and add it to buffer
client.Timing("a.b.d", 43)                     # set timing metric "prefix.a.b.d" and add it to buffer
client.Flush()                                 # send all metrics as one packet to StatsD

See also

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

The Client type

func NewBufferedClient

func NewBufferedClient(host string, port int) *Client

NewBufferedClient creates new StatsD client with enabled buffer. If flush interval not defined, manual call of Flush() required to send metrics to StatsD server.

func NewClient

func NewClient(host string, port int) *Client

NewClient creates new StatsD client with disabled buffer.

func (*Client) Close

func (client *Client) Close()

Close UDP connection to statsd server

func (*Client) Count

func (client *Client) Count(key string, value int, sampleRate float32)

Count tack

func (*Client) Flush

func (client *Client) Flush() error

Flush buffer to statsd daemon by UDP when buffer disabled

func (*Client) Gauge

func (client *Client) Gauge(key string, value int)

Gauge track To set a gauge to a negative number you need first set it to 0, because negative value interprets as negative shift.

func (*Client) GaugeShift

func (client *Client) GaugeShift(key string, value int)

GaugeShift decrease previously set value if negative value passed, and increase if positive.

func (*Client) Open

func (client *Client) Open()

Open UDP connection to statsd server

func (*Client) Set

func (client *Client) Set(key string, value int)

Set tracking

func (*Client) SetFlushInterval added in v1.1.2

func (client *Client) SetFlushInterval(flushInterval time.Duration)

func (*Client) SetPrefix added in v1.1.1

func (client *Client) SetPrefix(metricPrefix string)

SetPrefix adds prefix to all keys

func (*Client) Timing

func (client *Client) Timing(key string, time int64, sampleRate float32)

Timing track in milliseconds with sampling

Jump to

Keyboard shortcuts

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