Documentation ¶
Overview ¶
Package dogstatsd provides a DogStatsD backend for package metrics. It's very similar to StatsD, but supports arbitrary tags per-metric, which map to Go kit's label values. So, while label values are no-ops in StatsD, they are supported here. For more details, see the documentation at http://docs.datadoghq.com/guides/dogstatsd/.
This package batches observations and emits them on some schedule to the remote server. This is useful even if you connect to your DogStatsD server over UDP. Emitting one network packet per observation can quickly overwhelm even the fastest internal network.
Index ¶
- type Counter
- type Dogstatsd
- func (d *Dogstatsd) NewCounter(name string, sampleRate float64) *Counter
- func (d *Dogstatsd) NewGauge(name string) *Gauge
- func (d *Dogstatsd) NewHistogram(name string, sampleRate float64) *Histogram
- func (d *Dogstatsd) NewTiming(name string, sampleRate float64) *Timing
- func (d *Dogstatsd) SendLoop(c <-chan time.Time, network, address string)
- func (d *Dogstatsd) WriteLoop(c <-chan time.Time, w io.Writer)
- func (d *Dogstatsd) WriteTo(w io.Writer) (count int64, err error)
- type Gauge
- type Histogram
- type Timing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶ added in v0.3.0
type Counter struct {
// contains filtered or unexported fields
}
Counter is a DogStatsD counter. Observations are forwarded to a Dogstatsd object, and aggregated (summed) per timeseries.
type Dogstatsd ¶ added in v0.3.0
type Dogstatsd struct {
// contains filtered or unexported fields
}
Dogstatsd receives metrics observations and forwards them to a DogStatsD server. Create a Dogstatsd object, use it to create metrics, and pass those metrics as dependencies to the components that will use them.
All metrics are buffered until WriteTo is called. Counters and gauges are aggregated into a single observation per timeseries per write. Timings and histograms are buffered but not aggregated.
To regularly report metrics to an io.Writer, use the WriteLoop helper method. To send to a DogStatsD server, use the SendLoop helper method.
func New ¶ added in v0.3.0
New returns a Dogstatsd object that may be used to create metrics. Prefix is applied to all created metrics. Callers must ensure that regular calls to WriteTo are performed, either manually or with one of the helper methods.
func (*Dogstatsd) NewCounter ¶ added in v0.3.0
NewCounter returns a counter, sending observations to this Dogstatsd object.
func (*Dogstatsd) NewGauge ¶ added in v0.3.0
NewGauge returns a gauge, sending observations to this Dogstatsd object.
func (*Dogstatsd) NewHistogram ¶ added in v0.3.0
NewHistogram returns a histogram whose observations are of an unspecified unit, and are forwarded to this Dogstatsd object.
func (*Dogstatsd) NewTiming ¶ added in v0.3.0
NewTiming returns a histogram whose observations are interpreted as millisecond durations, and are forwarded to this Dogstatsd object.
func (*Dogstatsd) SendLoop ¶ added in v0.3.0
SendLoop is a helper method that wraps WriteLoop, passing a managed connection to the network and address. Like WriteLoop, this method blocks until the channel is closed, so clients probably want to start it in its own goroutine. For typical usage, create a time.Ticker and pass its C channel to this method.
func (*Dogstatsd) WriteLoop ¶ added in v0.3.0
WriteLoop is a helper method that invokes WriteTo to the passed writer every time the passed channel fires. This method blocks until the channel is closed, so clients probably want to run it in its own goroutine. For typical usage, create a time.Ticker and pass its C channel to this method.
func (*Dogstatsd) WriteTo ¶ added in v0.3.0
WriteTo flushes the buffered content of the metrics to the writer, in DogStatsD format. WriteTo abides best-effort semantics, so observations are lost if there is a problem with the write. Clients should be sure to call WriteTo regularly, ideally through the WriteLoop or SendLoop helper methods.
type Gauge ¶ added in v0.3.0
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a DogStatsD gauge. Observations are forwarded to a Dogstatsd object, and aggregated (the last observation selected) per timeseries.
type Histogram ¶ added in v0.3.0
type Histogram struct {
// contains filtered or unexported fields
}
Histogram is a DogStatsD histrogram. Observations are forwarded to a Dogstatsd object, and collected (but not aggregated) per timeseries.
type Timing ¶ added in v0.3.0
type Timing struct {
// contains filtered or unexported fields
}
Timing is a DogStatsD timing, or metrics.Histogram. Observations are forwarded to a Dogstatsd object, and collected (but not aggregated) per timeseries.