metrics

package
v0.8.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2014 License: Apache-2.0, MIT, Apache-2.0 Imports: 10 Imported by: 0

README

metrics

Go library for emitting metrics to StatsD.

Originally: https://github.com/cactus/go-statsd-client

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Close closes the connection and cleans up.
	Close() error

	// Increments a statsd count type.
	// stat is a string name for the metric.
	// value is the integer value
	// rate is the sample rate (0.0 to 1.0)
	Inc(stat interface{}, value int64, rate float32) error

	// Decrements a statsd count type.
	// stat is a string name for the metric.
	// value is the integer value.
	// rate is the sample rate (0.0 to 1.0).
	Dec(stat interface{}, value int64, rate float32) error

	// Submits/Updates a statsd gauge type.
	// stat is a string name for the metric.
	// value is the integer value.
	// rate is the sample rate (0.0 to 1.0).
	Gauge(stat interface{}, value int64, rate float32) error

	// Submits a delta to a statsd gauge.
	// stat is the string name for the metric.
	// value is the (positive or negative) change.
	// rate is the sample rate (0.0 to 1.0).
	GaugeDelta(stat interface{}, value int64, rate float32) error

	// Submits a statsd timing type.
	// stat is a string name for the metric.
	// value is the integer value.
	// rate is the sample rate (0.0 to 1.0).
	Timing(stat interface{}, delta int64, rate float32) error

	// Emit duration in milliseconds
	TimingMs(stat interface{}, tm time.Duration, rate float32) error

	// Submits a stats set type, where value is the unique string
	// rate is the sample rate (0.0 to 1.0).
	UniqueString(stat interface{}, value string, rate float32) error

	// Submits a stats set type
	// rate is the sample rate (0.0 to 1.0).
	UniqueInt64(stat interface{}, value int64, rate float32) error

	// Reports runtime metrics
	ReportRuntimeMetrics(prefix string, rate float32) error

	// Sets/Updates the statsd client prefix
	SetPrefix(prefix string)

	Metric(p ...string) Metric
}

func New

func New(addr, prefix string) (Client, error)

New returns a new statsd Client, and an error. addr is a string of the format "hostname:port", and must be parsable by net.ResolveUDPAddr. prefix is the statsd client prefix. Can be "" if no prefix is desired.

func NewNop

func NewNop() Client

func NewWithOptions

func NewWithOptions(addr, prefix string, opts Options) (Client, error)

type Metric

type Metric interface {
	// Metric is a composer that creates a new metric by cloning the current metric and adding
	// values to it, is useful for cases with multiple submetric of the same metric
	// m := s.Metric("base")
	// m.Metric("roundtrip")
	// m.Metric("bytes")
	Metric(p ...string) Metric
	String() string
}

Metric is an interface that represents system metric, provides platform-specific escaping and is faster than using fmt.Sprintf() as it usually uses bytes.Buffer

func NewMetric

func NewMetric(prefix string, p ...string) Metric

type Options

type Options struct {
	// UseBuffering turns on buffering of metrics what reduces amount of UDP packets
	UseBuffering bool
	// FlushBytes will trigger the packet send whenever accumulated buffer size will reach this value, default is 1440
	FlushBytes int
	// FlushPeriod will trigger periodic flushes in case of inactivity to avoid metric loss
	FlushPeriod time.Duration
}

StatsdOptions allows tuning client for efficiency

type UDPSender

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

func (*UDPSender) Close

func (s *UDPSender) Close() error

func (*UDPSender) Write

func (s *UDPSender) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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