Documentation
¶
Overview ¶
Package Meter yields summarized data describing a series of timed events.
Index ¶
- Constants
- Variables
- type ClientOptions
- type Config
- type Option
- func BufPoolCapacity(capacity int) Option
- func DefaultTags(tags ...Tag) Option
- func FlushInterval(interval time.Duration) Option
- func Logger(logger SomeLogger) Option
- func MaxPacketSize(packetSize int) Option
- func MetricPrefix(prefix string) Option
- func ReconnectInterval(interval time.Duration) Option
- func ReportInterval(interval time.Duration) Option
- func RetryTimeout(timeout time.Duration) Option
- func SendLoopCount(threads int) Option
- func SendQueueCapacity(capacity int) Option
- func TagStyle(style *TagFormat) Option
- type SomeLogger
- type Stats
- func (s *Stats) Decr(stat string, count int64, tags ...Tag)
- func (s *Stats) Incr(stat string, count int64, tags ...Tag)
- func (s *Stats) PrecisionTiming(stat string, delta time.Duration, tags ...Tag)
- func (s *Stats) SetAdd(stat string, value string, tags ...Tag)
- func (s *Stats) Timing(stat string, delta int64, tags ...Tag)
- func (s *Stats) Unregister()
- type Tag
- type TagFormat
Constants ¶
const ( DefaultMaxPacketSize = 1432 DefaultMetricPrefix = "" DefaultFlushInterval = 100 * time.Millisecond DefaultReconnectInterval = time.Duration(0) DefaultReportInterval = time.Minute DefaultRetryTimeout = 5 * time.Second DefaultLogPrefix = "[STATSD] " DefaultBufPoolCapacity = 20 DefaultSendQueueCapacity = 10 DefaultSendLoopCount = 1 )
Default settings
const ( TagPlacementName = iota TagPlacementSuffix )
Tag placement constants
Variables ¶
var ( // TagFormatInfluxDB is format for InfluxDB StatsD telegraf plugin // // Docs: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/statsd TagFormatInfluxDB = &TagFormat{ Placement: TagPlacementName, FirstSeparator: ",", OtherSeparator: ',', KeyValueSeparator: '=', } // TagFormatDatadog is format for DogStatsD (Datadog Agent) // // Docs: https://docs.datadoghq.com/developers/dogstatsd/#datagram-format TagFormatDatadog = &TagFormat{ Placement: TagPlacementSuffix, FirstSeparator: "|#", OtherSeparator: ',', KeyValueSeparator: ':', } )
Functions ¶
This section is empty.
Types ¶
type ClientOptions ¶
type ClientOptions struct { // Addr is statsd server address in "host:port" format Addr string Size int HBins int // Histogram bins. // MetricPrefix is metricPrefix to prepend to every metric being sent // // If not set defaults to empty string MetricPrefix string // MaxPacketSize is maximum UDP packet size // // Safe value is 1432 bytes, if your network supports jumbo frames, // this value could be raised up to 8960 bytes MaxPacketSize int // FlushInterval controls flushing incomplete UDP packets which makes // sure metric is not delayed longer than FlushInterval // // Default value is 100ms, setting FlushInterval to zero disables flushing FlushInterval time.Duration // ReconnectInterval controls UDP socket reconnects // // Reconnecting is important to follow DNS changes, e.g. in // dynamic container environments like K8s where statsd server // instance might be relocated leading to new IP address. // // By default reconnects are disabled ReconnectInterval time.Duration // RetryTimeout controls how often client should attempt reconnecting // to statsd server on failure // // Default value is 5 seconds RetryTimeout time.Duration // ReportInterval instructs client to report number of packets lost // each interval via Logger // // By default lost packets are reported every minute, setting to zero // disables reporting ReportInterval time.Duration // Logger is used by statsd client to report errors and lost packets // // If not set, default logger to stderr with metricPrefix `[STATSD] ` is being used Logger SomeLogger // BufPoolCapacity controls size of pre-allocated buffer cache // // Each buffer is MaxPacketSize. Cache allows to avoid allocating // new buffers during high load // // Default value is DefaultBufPoolCapacity BufPoolCapacity int // SendQueueCapacity controls length of the queue of packet ready to be sent // // Packets might stay in the queue during short load bursts or while // client is reconnecting to statsd // // Default value is DefaultSendQueueCapacity SendQueueCapacity int // SendLoopCount controls number of goroutines sending UDP packets // // Default value is 1, so packets are sent from single goroutine, this // value might need to be bumped under high load SendLoopCount int // TagFormat controls formatting of StatsD tags // // If tags are not used, value of this setting isn't used. // // There are two predefined formats: for InfluxDB and Datadog, default // format is InfluxDB tag format. TagFormat *TagFormat // DefaultTags is a list of tags to be applied to every metric DefaultTags []Tag }
ClientOptions are statsd client settings
type Config ¶
Config holds Meter initialization parameters. Size defines the sample capacity. Meter is thread safe.
type Option ¶
type Option func(c *ClientOptions)
Option is type for option transport
func BufPoolCapacity ¶
BufPoolCapacity controls size of pre-allocated buffer cache
Each buffer is MaxPacketSize. Cache allows to avoid allocating new buffers during high load
Default value is DefaultBufPoolCapacity
func DefaultTags ¶
DefaultTags defines a list of tags to be applied to every metric
func FlushInterval ¶
FlushInterval controls flushing incomplete UDP packets which makes sure metric is not delayed longer than FlushInterval
Default value is 100ms, setting FlushInterval to zero disables flushing
func Logger ¶
func Logger(logger SomeLogger) Option
Logger is used by statsd client to report errors and lost packets
If not set, default logger to stderr with metricPrefix `[STATSD] ` is being used
func MaxPacketSize ¶
MaxPacketSize control maximum UDP packet size
Default value is DefaultMaxPacketSize
func MetricPrefix ¶
MetricPrefix is metricPrefix to prepend to every metric being sent
Usually metrics are prefixed with app name, e.g. `app.`. To avoid providing this metricPrefix for every metric being collected, and to enable shared libraries to collect metric under app name, use MetricPrefix to set global metricPrefix for all the app metrics, e.g. `MetricPrefix("app".)`.
If not set defaults to empty string
func ReconnectInterval ¶
ReconnectInterval controls UDP socket reconnects
Reconnecting is important to follow DNS changes, e.g. in dynamic container environments like K8s where statsd server instance might be relocated leading to new IP address.
By default reconnects are disabled
func ReportInterval ¶
ReportInterval instructs client to report number of packets lost each interval via Logger
By default lost packets are reported every minute, setting to zero disables reporting
func RetryTimeout ¶
RetryTimeout controls how often client should attempt reconnecting to statsd server on failure
Default value is 5 seconds
func SendLoopCount ¶
SendLoopCount controls number of goroutines sending UDP packets
Default value is 1, so packets are sent from single goroutine, this value might need to be bumped under high load
func SendQueueCapacity ¶
SendQueueCapacity controls length of the queue of packet ready to be sent
Packets might stay in the queue during short load bursts or while client is reconnecting to statsd
Default value is DefaultSendQueueCapacity
type SomeLogger ¶
type SomeLogger interface {
Printf(fmt string, args ...interface{})
}
SomeLogger defines logging interface that allows using 3rd party loggers (e.g. github.com/sirupsen/logrus) with this Statsd client.
type Stats ¶
Meter holds event durations and counts.
func (*Stats) Incr ¶
Incr increments a counter metric
Often used to note a particular event, for example incoming web request.
func (*Stats) PrecisionTiming ¶
PrecisionTiming track a duration event, the time delta has to be a duration
Usually request processing time, time to run database query, etc. are used with this metric type.
func (*Stats) SetAdd ¶
SetAdd adds unique element to a set
Statsd server will provide cardinality of the set over aggregation period.
func (*Stats) Unregister ¶
func (s *Stats) Unregister()
type TagFormat ¶
type TagFormat struct { // FirstSeparator is put after metric name and before first tag FirstSeparator string // Placement specifies part of the message to append tags to Placement byte // OtherSeparator separates 2nd and subsequent tags from each other OtherSeparator byte // KeyValueSeparator separates tag name and tag value KeyValueSeparator byte }
TagFormat controls tag formatting style