statsd

package
v0.0.0-...-059b1e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2021 License: MIT Imports: 9 Imported by: 7

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) (sink metric.Sink, err error)

New creasted a SinkFactory which is used to create Sinks sending data to a UDP statsd server Provide a UDP address, a prefix and a maximum UDP datagram size. 1432 should be a safe size for most nets.

Example
package main

import (
	"github.com/One-com/gone/metric"
	"github.com/One-com/gone/metric/sink/statsd"
	"log"
	"os"
	"time"
)

func main() {
	var sink metric.Sink
	var err error

	sink, err = statsd.New(
		statsd.Buffer(512),
		statsd.Output(os.Stdout),
		statsd.Prefix("prefix"))
	if err != nil {
		log.Fatal(err)
	}

	gauge := metric.NewGauge("gauge")
	counter := metric.NewCounter("counter")
	histo := metric.NewHistogram("histo")
	timer := metric.NewTimer("timer")
	set := metric.NewSet("set")

	timer.Sample(time.Second)
	timer.Sample(time.Millisecond)
	gauge.Set(17)
	histo.Sample(123456)
	counter.Inc(2)
	counter.Inc(3)
	set.Add("member")
	set.Add("member")

	timer.FlushReading(sink)
	gauge.FlushReading(sink)
	counter.FlushReading(sink)
	histo.FlushReading(sink)
	set.FlushReading(sink)
	sink.Flush()
}
Output:

prefix.timer:1000|ms
prefix.timer:1|ms
prefix.gauge:17|g
prefix.counter:5|c
prefix.histo:123456|ms
prefix.set:member|s

Types

type Option

type Option func(*Sink) error

Option is the type of configuration options for the statsd sink factory.

func Buffer

func Buffer(size int) Option

Buffer sets the package size with which writes to the underlying io.Writer (often an UDPConn) is done.

func Output

func Output(w io.Writer) Option

Output sets an general io.Writer as output instead of a UDPConn.

func Peer

func Peer(addr string) Option

Peer is the address of the statsd UDP server

func Prefix

func Prefix(pfx string) Option

Prefix is prepended with "prefix." to all metric names

type Sink

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

Sink is a go-routine safe version of a Statsd sink. Call UnlockedSink() to get a faster, but not go-routine safe Sink.

func (*Sink) Flush

func (s *Sink) Flush()

func (*Sink) Record

func (s *Sink) Record(mtype int, name string, value interface{})

Record a value with the sink

func (*Sink) RecordNumeric64

func (s *Sink) RecordNumeric64(mtype int, name string, value num64.Numeric64)

Record a Numeric64 value with the sink

func (*Sink) UnlockedSink

func (s *Sink) UnlockedSink() metric.Sink

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL