gostc

package
v0.0.0-...-60e5113 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2015 License: MIT, MIT Imports: 6 Imported by: 0

README

gostc

GoDoc

gostc is a Go StatsD/gost client.

Installation

go get github.com/cespare/gostc

Usage

Quick example:

client, err := gostc.NewClient("localhost:8125")
if err != nil {
  panic(err)
}

// Users will typically ignore the return errors of gostc methods as statsd
// is a best-effort service in most software.
client.Count("foobar", 1, 1)
client.Inc("foobar") // Same as above
t := time.Now()
time.Sleep(time.Second)
client.Time("blah", time.Since(t))

Documentation

Overview

Package gostc implemenents a StatsD/gost client.

This package performs minimal input validation, leaving that to the gost server.

Index

Constants

View Source
const (
	// 100 * DefaultMaxPacketBytes = 10KB, as a lower bound on memory usage.
	DefaultQueueSize = 100
	// 1/10th of gost's default max, and 1k packets seem to generally work for Linux local UDP.
	DefaultMaxPacketBytes = 1000
	DefaultMinFlush       = time.Second
)

Variables

View Source
var ErrSamplingRate = errors.New("sampling rate must be in (0, 1]")

ErrSamplingRate is returned by client.Count (or variants) when a bad sampling rate value is provided.

Functions

This section is empty.

Types

type Client

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

A Client is a StatsD/gost client which has a UDP connection.

func NewBufferedClient

func NewBufferedClient(addr string, queueSize int, maxPacketBytes int, minFlush time.Duration) (*Client, error)

NewBufferedClient creates a client with the given UDP address that can buffer messages and sends them together in batches (separated by newlines, per the statsd protocol). Messages are formatted and sent to a single sending goroutine via a buffered channel. This has the effect of offloading the CPU and clock time of sending the messages from the calling goroutine, as well as possibly increasing efficiency by reducing the volume of UDP packets sent.

A buffered Client may or may not change (improve, degrade) performance in your particular scenario. Default to using a normal client (via NewClient) unless gostc performance is a measurable bottleneck, and then see if a buffered client helps (and keep measuring).

The three parameters queueSize, maxPacketBytes, and minFlush tune the buffered channel size, maximum single packet size, and minimum time between flushes. Message are buffered until maxPacketBytes is reached or until some time as passed (no more than minFlush). Use NewDefaultBufferedClient for reasonable defaults.

Note that a buffered client cannot report UDP errors (it will silently fail).

func NewClient

func NewClient(addr string) (*Client, error)

NewClient creates a client with the given UDP address.

func NewDefaultBufferedClient

func NewDefaultBufferedClient(addr string) (*Client, error)

NewDefaultBufferedClient calls NewBufferedClient with tuning parameters queueSize, maxPacketBytes, and minFlush set to DefaultQueueSize, DefaultMaxPacketBytes, and DefaultMinFlush, respectively.

func (*Client) Close

func (c *Client) Close() error

Close closes the client's UDP connection. Afterwards, the client cannot be used. If the client is buffered, Close first sends any buffered messages.

func (*Client) Count

func (c *Client) Count(key string, delta, samplingRate float64) error

Count submits a statsd count message with the given key, value, and sampling rate.

func (*Client) CountProb

func (c *Client) CountProb(key string, delta, p float64) error

CountProb counts (key, delta) with probability p in (0, 1].

func (*Client) Gauge

func (c *Client) Gauge(key string, value float64) error

Gauge submits a statsd gauge message.

func (*Client) Inc

func (c *Client) Inc(key string) error

Inc submits a count with delta and sampling rate equal to 1.

func (*Client) IncProb

func (c *Client) IncProb(key string, p float64) error

IncProb increments key with probability p in (0, 1].

func (*Client) Set

func (c *Client) Set(key string, element []byte) error

Set submits a statsd set message.

func (*Client) Time

func (c *Client) Time(key string, duration time.Duration) error

Time submits a statsd timer message.

Jump to

Keyboard shortcuts

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