Version: v3.1.1+incompatible Latest Latest

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

Go to latest
Published: Jan 19, 2018 License: MIT Imports: 5 Imported by: 2




This section is empty.


This section is empty.


This section is empty.


type RecordingSender

type RecordingSender struct {
	// contains filtered or unexported fields

RecordingSender implements statsd.Sender but parses individual Stats into a buffer that can be later inspected instead of sending to some server. It should constructed with NewRecordingSender().

func NewRecordingSender

func NewRecordingSender() *RecordingSender

NewRecordingSender creates a new RecordingSender for use by a statsd.Client.

func (*RecordingSender) ClearSent

func (rs *RecordingSender) ClearSent()

ClearSent locks the sender and clears any Stats that have been recorded.

func (*RecordingSender) Close

func (rs *RecordingSender) Close() error

Close marks this sender as closed. Subsequent attempts to Send stats will result in an error.

func (*RecordingSender) GetSent

func (rs *RecordingSender) GetSent() Stats

GetSent returns the stats that have been sent. Locks and copies the current state of the sent Stats.

The entire buffer of Stat objects (including Stat.Raw is copied).

func (*RecordingSender) Send

func (rs *RecordingSender) Send(data []byte) (int, error)

Send parses the provided []byte into stat objects and then appends these to the buffer of sent stats. Buffer operations are synchronized so it is safe to call this from multiple goroutines (though contenion will impact performance so don't use this during a benchmark). Send treats '\n' as a delimiter between multiple sats in the same []byte.

Calling after the Sender has been closed will return an error (and not mutate the buffer).

type Stat

type Stat struct {
	Raw    []byte
	Stat   string
	Value  string
	Tag    string
	Rate   string
	Parsed bool

Stat contains the raw and extracted stat information from a stat that was sent by the RecordingSender. Raw will always have the content that was consumed for this specific stat and Parsed will be set if no errors were hit pulling information out of it.

func (*Stat) String

func (s *Stat) String() string

String fulfils the stringer interface

type Stats

type Stats []Stat

Stats is a slice of Stat

func ParseStats

func ParseStats(src []byte) Stats

ParseStats takes a sequence of bytes destined for a Statsd server and parses it out into one or more Stat structs. Each struct includes both the raw bytes (copied, so the src []byte may be reused if desired) as well as each component it was able to parse out. If parsing was incomplete Stat.Parsed will be set to false but no error is returned / kept.

func (Stats) Collect

func (s Stats) Collect(pred func(Stat) bool) Stats

Collect gathers all stats that make some predicate true.

func (Stats) CollectNamed

func (s Stats) CollectNamed(statName string) Stats

CollectNamed returns all data sent for a given stat name.

func (Stats) String

func (s Stats) String() string

String fulfils the stringer interface

func (Stats) Unparsed

func (s Stats) Unparsed() Stats

Unparsed returns any stats that were unable to be completely parsed.

func (Stats) Values

func (s Stats) Values() []string

Values returns the values associated with this Stats object.

Jump to

Keyboard shortcuts

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