Documentation ¶
Overview ¶
Package statsd implements a client and a debugging server for UDP statsd datagrams.
Index ¶
- Constants
- func IsErrUseOfClosedNetworkConnection(err error) bool
- func NewUDPListener(addr string) (net.PacketConn, error)
- func NewUnixgramListener(path string) (net.PacketConn, error)
- func Tag(k, v string) string
- type Client
- func (c *Client) AddDefaultTag(name, value string)
- func (c *Client) AddDefaultTags(tags ...string)
- func (c *Client) Close() error
- func (c *Client) Count(name string, value int64, tags ...string) error
- func (c *Client) DefaultTags() []string
- func (c *Client) Distribution(name string, value float64, tags ...string) error
- func (c *Client) Flush() error
- func (c *Client) Gauge(name string, value float64, tags ...string) error
- func (c *Client) Histogram(name string, value float64, tags ...string) error
- func (c *Client) Increment(name string, tags ...string) error
- func (c *Client) TimeInMilliseconds(name string, value time.Duration, tags ...string) error
- type ClientOpt
- type Config
- type Metric
- type Server
Constants ¶
const ( ErrAddrUnset ex.Class = "statsd client address unset" ErrMaxPacketSize ex.Class = "statsd max packet size exceeded" ErrSampleRateInvalid ex.Class = "statsd invalid sample rate" )
Error classes.
const ( DefaultDialTimeout = time.Second DefaultMaxPacketSize = 1 << 12 // 2^12 or 4kB DefaultMaxBufferSize = 32 )
Constants
const ( MetricTypeCount = "c" MetricTypeGauge = "g" MetricTypeHistogram = "h" MetricTypeDistribution = "d" MetricTypeTimer = "ms" )
MetricTypes
Variables ¶
This section is empty.
Functions ¶
func IsErrUseOfClosedNetworkConnection ¶ added in v1.20210103.1
IsErrUseOfClosedNetworkConnection is an error class checker.
func NewUDPListener ¶
func NewUDPListener(addr string) (net.PacketConn, error)
NewUDPListener returns a new UDP listener for a given address.
func NewUnixgramListener ¶ added in v1.20210103.1
func NewUnixgramListener(path string) (net.PacketConn, error)
NewUnixgramListener returns a new unixgram listener for a given path.
Types ¶
type Client ¶
type Client struct { Addr string DialTimeout time.Duration MaxPacketSize int SampleProvider func() bool MaxBufferSize int // contains filtered or unexported fields }
Client is a statsd client.
func (*Client) AddDefaultTag ¶
AddDefaultTag adds a new default tag.
func (*Client) AddDefaultTags ¶
AddDefaultTags adds default tags.
func (*Client) DefaultTags ¶
DefaultTags returns the default tags.
func (*Client) Distribution ¶ added in v1.20210103.1
Distribution is an no-op for raw statsd.
type ClientOpt ¶
ClientOpt is an option for a client.
func OptDialTimeout ¶
OptDialTimeout sets the client dial timeout.
func OptMaxBufferSize ¶
OptMaxBufferSize sets the client max buffer size in messages.
func OptMaxPacketSize ¶
OptMaxPacketSize sets the client max dial size.
func OptSampleRate ¶
OptSampleRate sets the sample rate on the client or the percent of packets to send on the interval [0,1.0). A value of `0.0` will drop all packets, a value of `1.0` will send all packets.
type Config ¶
type Config struct { Addr string `json:"addr" yaml:"addr" env:"STATSD_ADDR"` DialTimeout time.Duration `json:"dialTimeout" yaml:"dialTimeout"` SampleRate float64 `json:"sampleRate" yaml:"sampleRate"` MaxPacketSize int `json:"maxPacketSize" yaml:"maxPacketSize"` MaxBufferSize int `json:"maxBufferSize" yaml:"maxBufferSize"` DefaultTags map[string]string `json:"defaultTags" yaml:"defaultTags"` }
Config is the set of options for the statsd client.
type Metric ¶
Metric is a statsd metric.
func (Metric) Duration ¶
Duration is the value parsed as a duration assuming it was a float64 of milliseconds.
type Server ¶
type Server struct { Addr string Log *log.Logger MaxPacketSize int Listener net.PacketConn Handler func(...Metric) }
Server is a listener for statsd metrics. It is meant to be used for diagnostic purposes, and is not suitable for production anything.
func (*Server) MaxPacketSizeOrDefault ¶
MaxPacketSizeOrDefault returns the max packet size or a default.