kit: github.com/go-kit/kit/metrics/influxstatsd Index | Files

package influxstatsd

import "github.com/go-kit/kit/metrics/influxstatsd"

Package influxstatsd provides support for InfluxData's StatsD Telegraf plugin. 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 article at https://www.influxdata.com/blog/getting-started-with-sending-statsd-metrics-to-telegraf-influxdb/

This package batches observations and emits them on some schedule to the remote server. This is useful even if you connect to your service over UDP. Emitting one network packet per observation can quickly overwhelm even the fastest internal network.

Index

Package Files

influxstatsd.go

type Counter Uses

type Counter struct {
    // contains filtered or unexported fields
}

Counter is a InfluxStatsD counter. Observations are forwarded to a Influxstatsd object, and aggregated (summed) per timeseries.

func (*Counter) Add Uses

func (c *Counter) Add(delta float64)

Add implements metrics.Counter.

func (*Counter) With Uses

func (c *Counter) With(labelValues ...string) metrics.Counter

With implements metrics.Counter.

type Gauge Uses

type Gauge struct {
    // contains filtered or unexported fields
}

Gauge is a InfluxStatsD gauge. Observations are forwarded to a Influxstatsd object, and aggregated (the last observation selected) per timeseries.

func (*Gauge) Add Uses

func (g *Gauge) Add(delta float64)

Add implements metrics.Gauge.

func (*Gauge) Set Uses

func (g *Gauge) Set(value float64)

Set implements metrics.Gauge.

func (*Gauge) With Uses

func (g *Gauge) With(labelValues ...string) metrics.Gauge

With implements metrics.Gauge.

type Histogram Uses

type Histogram struct {
    // contains filtered or unexported fields
}

Histogram is a InfluxStatsD histrogram. Observations are forwarded to a Influxstatsd object, and collected (but not aggregated) per timeseries.

func (*Histogram) Observe Uses

func (h *Histogram) Observe(value float64)

Observe implements metrics.Histogram.

func (*Histogram) With Uses

func (h *Histogram) With(labelValues ...string) metrics.Histogram

With implements metrics.Histogram.

type Influxstatsd Uses

type Influxstatsd struct {
    // contains filtered or unexported fields
}

Influxstatsd receives metrics observations and forwards them to a server. Create a Influxstatsd 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 InfluxStatsD server, use the SendLoop helper method.

func New Uses

func New(prefix string, logger log.Logger, lvs ...string) *Influxstatsd

New returns a Influxstatsd 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 (*Influxstatsd) NewCounter Uses

func (d *Influxstatsd) NewCounter(name string, sampleRate float64) *Counter

NewCounter returns a counter, sending observations to this Influxstatsd object.

func (*Influxstatsd) NewGauge Uses

func (d *Influxstatsd) NewGauge(name string) *Gauge

NewGauge returns a gauge, sending observations to this Influxstatsd object.

func (*Influxstatsd) NewHistogram Uses

func (d *Influxstatsd) NewHistogram(name string, sampleRate float64) *Histogram

NewHistogram returns a histogram whose observations are of an unspecified unit, and are forwarded to this Influxstatsd object.

func (*Influxstatsd) NewTiming Uses

func (d *Influxstatsd) NewTiming(name string, sampleRate float64) *Timing

NewTiming returns a histogram whose observations are interpreted as millisecond durations, and are forwarded to this Influxstatsd object.

func (*Influxstatsd) SendLoop Uses

func (d *Influxstatsd) SendLoop(c <-chan time.Time, network, address string)

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 (*Influxstatsd) WriteLoop Uses

func (d *Influxstatsd) WriteLoop(c <-chan time.Time, w io.Writer)

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 (*Influxstatsd) WriteTo Uses

func (d *Influxstatsd) WriteTo(w io.Writer) (count int64, err error)

WriteTo flushes the buffered content of the metrics to the writer, in InfluxStatsD 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 Uses

type Timing struct {
    // contains filtered or unexported fields
}

Timing is a InfluxStatsD timing, or metrics.Histogram. Observations are forwarded to a Influxstatsd object, and collected (but not aggregated) per timeseries.

func (*Timing) Observe Uses

func (t *Timing) Observe(value float64)

Observe implements metrics.Histogram. Value is interpreted as milliseconds.

func (*Timing) With Uses

func (t *Timing) With(labelValues ...string) metrics.Histogram

With implements metrics.Timing.

Package influxstatsd imports 12 packages (graph). Updated 2018-03-30. Refresh now. Tools for package owners.