statsd

package
v0.0.0-...-d581741 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package statsd implements functionality for creating servers compatible with the statsd protocol. See https://github.com/b/statsd_spec for a description of the protocol.

The main components of the library are MetricReceiver and MetricAggregator, which are responsible for receiving and aggregating the metrics respectively. MetricAggregator receives Metric objects via its MetricChan and then aggregates them based on their type. At every FlushInterval the metrics are flushed via the aggregator's associated MetricSender object.

Currently the library implements just one type MetricSender, compatible with Graphite (http://graphite.wikidot.org), but any object implementing the MetricSender interface can be used with the library.

Index

Constants

View Source
const DefaultConsoleAddr = ":8126"

DefaultConsoleAddr is the default address on which a ConsoleServer will listen

View Source
const DefaultMetricsAddr = ":8125"

DefaultMetricsAddr is the default address on which a MetricReceiver will listen

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleServer

type ConsoleServer struct {
	Addr       string
	Aggregator *MetricAggregator
}

ConsoleServer is an object that listens for telnet connection on a TCP address Addr and provides a console interface to a manage a MetricAggregator

func (*ConsoleServer) ListenAndServe

func (s *ConsoleServer) ListenAndServe() error

ListenAndServe listens on the ConsoleServer's TCP network address and then calls Serve

func (*ConsoleServer) Serve

func (s *ConsoleServer) Serve(l net.Listener) error

Serve accepts incoming connections on the listener and serves them a console interface to the MetricAggregator

type GraphiteClient

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

GraphiteClient is an object that is used to send messages to a Graphite server's UDP interface

func NewGraphiteClient

func NewGraphiteClient(addr string) (client GraphiteClient, err error)

NewGraphiteClient constructs a GraphiteClient object by connecting to an address

func (*GraphiteClient) SendMetrics

func (client *GraphiteClient) SendMetrics(metrics MetricMap) (err error)

SendMetrics sends the metrics in a MetricsMap to the Graphite server

type Handler

type Handler interface {
	HandleMetric(m Metric)
}

Objects implementing the Handler interface can be used to handle metrics for a MetricReceiver

type HandlerFunc

type HandlerFunc func(Metric)

The HandlerFunc type is an adapter to allow the use of ordinary functions as metric handlers

func (HandlerFunc) HandleMetric

func (f HandlerFunc) HandleMetric(m Metric)

HandleMetric calls f(m)

type Metric

type Metric struct {
	Type   MetricType // The type of metric
	Bucket string     // The name of the bucket where the metric belongs
	Value  float64    // The numeric value of the metric
}

Metric represents a single data collected datapoint

func (Metric) String

func (m Metric) String() string

type MetricAggregator

type MetricAggregator struct {
	sync.Mutex
	MetricChan    chan Metric   // Channel on which metrics are received
	FlushInterval time.Duration // How often to flush metrics to the sender
	Sender        MetricSender  // The sender to which metrics are flushed
	Stats         metricAggregatorStats
	Counters      MetricMap
	Gauges        MetricMap
	Timers        MetricListMap
}

MetricAggregator is an object that aggregates statsd metrics. The function NewMetricAggregator should be used to create the objects.

Incoming metrics should be sent to the MetricChan channel.

func NewMetricAggregator

func NewMetricAggregator(sender MetricSender, flushInterval time.Duration) MetricAggregator

NewMetricAggregator creates a new MetricAggregator object

func (*MetricAggregator) Aggregate

func (a *MetricAggregator) Aggregate()

Aggregate starts the MetricAggregator so it begins consuming metrics from MetricChan and flushing them periodically via its Sender

func (*MetricAggregator) Reset

func (a *MetricAggregator) Reset()

Reset clears the contents of a MetricAggregator

type MetricListMap

type MetricListMap map[string][]float64

MetricListMap is simlar to MetricMap but instead of storing a single aggregated Metric value it stores a list of all collected values.

func (MetricListMap) String

func (m MetricListMap) String() string

type MetricMap

type MetricMap map[string]float64

MetricMap is used for storing aggregated Metric values. The keys of the map are metric bucket names.

func (MetricMap) String

func (m MetricMap) String() string

type MetricReceiver

type MetricReceiver struct {
	Addr    string  // UDP address on which to listen for metrics
	Handler Handler // handler to invoke
}

MetricReceiver receives data on its listening port and converts lines in to Metrics. For each Metric it calls r.Handler.HandleMetric()

func (*MetricReceiver) ListenAndReceive

func (r *MetricReceiver) ListenAndReceive() error

ListenAndReceive listens on the UDP network address of srv.Addr and then calls Receive to handle the incoming datagrams. If Addr is blank then DefaultMetricsAddr is used.

func (*MetricReceiver) Receive

func (r *MetricReceiver) Receive(c net.PacketConn) error

Receive accepts incoming datagrams on c and calls r.Handler.HandleMetric() for each line in the datagram that successfully parses in to a Metric

type MetricSender

type MetricSender interface {
	SendMetrics(MetricMap) error
}

MetricSender is an interface that can be implemented by objects which can provide metrics to a MetricAggregator

type MetricSenderFunc

type MetricSenderFunc func(MetricMap) error

The MetricSenderFunc type is an adapter to allow the use of ordinary functions as metric senders

func (MetricSenderFunc) SendMetrics

func (f MetricSenderFunc) SendMetrics(m MetricMap) error

SendMetrics calls f(m)

type MetricType

type MetricType float64

MetricType is an enumeration of all the possible types of Metric

const (
	ERROR MetricType = 1 << (10 * iota)
	COUNTER
	TIMER
	GAUGE
)

func (MetricType) String

func (m MetricType) String() string

type WebConsoleServer

type WebConsoleServer struct {
	Addr       string
	Aggregator *MetricAggregator
}

WebConsoleServer is an object that listens for HTTP connection on a TCP address Addr and provides a web interface for its MetricAggregator

func (*WebConsoleServer) ListenAndServe

func (s *WebConsoleServer) ListenAndServe() error

ListenAndServe listens on the ConsoleServer's TCP network address and then calls Serve

func (*WebConsoleServer) ServeHTTP

func (s *WebConsoleServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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