package statsd
import "github.com/go-kit/kit/metrics/statsd"
Package statsd provides a StatsD backend for package metrics. StatsD has no concept of arbitrary key-value tagging, so label values are not supported, and With is a no-op on all metrics.
This package batches observations and emits them on some schedule to the remote server. This is useful even if you connect to your StatsD server over UDP. Emitting one network packet per observation can quickly overwhelm even the fastest internal network.
Index ¶
- type Counter
- type Gauge
- func (g *Gauge) Add(delta float64)
- func (g *Gauge) Set(value float64)
- func (g *Gauge) With(...string) metrics.Gauge
- type Statsd
- func New(prefix string, logger log.Logger) *Statsd
- func (s *Statsd) NewCounter(name string, sampleRate float64) *Counter
- func (s *Statsd) NewGauge(name string) *Gauge
- func (s *Statsd) NewTiming(name string, sampleRate float64) *Timing
- func (s *Statsd) SendLoop(ctx context.Context, c <-chan time.Time, network, address string)
- func (s *Statsd) WriteLoop(ctx context.Context, c <-chan time.Time, w io.Writer)
- func (s *Statsd) WriteTo(w io.Writer) (count int64, err error)
- type Timing
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a StatsD counter. Observations are forwarded to a Statsd object, and aggregated (summed) per timeseries.
func (*Counter) Add ¶
Add implements metrics.Counter.
func (*Counter) With ¶
With is a no-op.
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a StatsD gauge. Observations are forwarded to a Statsd object, and aggregated (the last observation selected) per timeseries.
func (*Gauge) Add ¶
Add implements metrics.Gauge.
func (*Gauge) Set ¶
Set implements metrics.Gauge.
func (*Gauge) With ¶
With is a no-op.
type Statsd ¶
type Statsd struct {
// contains filtered or unexported fields
}
Statsd receives metrics observations and forwards them to a StatsD server. Create a Statsd 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 are buffered but not aggregated.
To regularly report metrics to an io.Writer, use the WriteLoop helper method. To send to a StatsD server, use the SendLoop helper method.
func New ¶
New returns a Statsd 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 (*Statsd) NewCounter ¶
NewCounter returns a counter, sending observations to this Statsd object.
func (*Statsd) NewGauge ¶
NewGauge returns a gauge, sending observations to this Statsd object.
func (*Statsd) NewTiming ¶
NewTiming returns a histogram whose observations are interpreted as millisecond durations, and are forwarded to this Statsd object.
func (*Statsd) SendLoop ¶
SendLoop is a helper method that wraps WriteLoop, passing a managed connection to the network and address. Like WriteLoop, this method blocks until ctx is canceled, 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 (*Statsd) WriteLoop ¶
WriteLoop is a helper method that invokes WriteTo to the passed writer every time the passed channel fires. This method blocks until ctx is canceled, 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 (*Statsd) WriteTo ¶
WriteTo flushes the buffered content of the metrics to the writer, in StatsD 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 Timing ¶
type Timing struct {
// contains filtered or unexported fields
}
Timing is a StatsD timing, or metrics.Histogram. Observations are forwarded to a Statsd object, and collected (but not aggregated) per timeseries.
func (*Timing) Observe ¶
Observe implements metrics.Histogram. Value is interpreted as milliseconds.
func (*Timing) With ¶
With is a no-op.
Source Files ¶
- Version
- v0.13.0 (latest)
- Published
- May 29, 2023
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 5 hours ago –
Tools for package owners.