Documentation ¶
Overview ¶
Package gostc implemenents a StatsD/gost client.
This package performs minimal input validation, leaving that to the gost server.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) Count(key string, delta, samplingRate float64) error
- func (c *Client) CountProb(key string, delta, p float64) error
- func (c *Client) Gauge(key string, value float64) error
- func (c *Client) Inc(key string) error
- func (c *Client) IncProb(key string, p float64) error
- func (c *Client) Set(key string, element []byte) error
- func (c *Client) Time(key string, duration time.Duration) error
Constants ¶
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 ¶
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 NewDefaultBufferedClient ¶
NewDefaultBufferedClient calls NewBufferedClient with tuning parameters queueSize, maxPacketBytes, and minFlush set to DefaultQueueSize, DefaultMaxPacketBytes, and DefaultMinFlush, respectively.
func (*Client) Close ¶
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 ¶
Count submits a statsd count message with the given key, value, and sampling rate.