Version: v0.0.0-...-8b1022e Latest Latest

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

Go to latest
Published: Jun 17, 2016 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0



Wraps a dialer to measure the delay, throughput and errors of a connection



Package measured wraps a dialer/listener to measure the throughput on those connections. Throughput is represented as total bytes sent/received between each interval.

ID is the remote address by default.

A list of reporters can be plugged in to send the results to different target.



This section is empty.


This section is empty.


This section is empty.


type Conn

type Conn struct {
	// arbitrary string to identify this connection, defaults to remote address
	ID string
	// total bytes read from this connection
	BytesIn uint64
	// total bytes wrote to this connection
	BytesOut uint64
	// contains filtered or unexported fields

Conn wraps any net.Conn to add statistics

func (*Conn) Close

func (mc *Conn) Close() (err error)

Close implements the function from net.Conn

func (*Conn) Read

func (mc *Conn) Read(b []byte) (n int, err error)

Read() implements the function from net.Conn

func (*Conn) Write

func (mc *Conn) Write(b []byte) (n int, err error)

Write() implements the function from net.Conn

type DialFunc

type DialFunc func(net, addr string) (net.Conn, error)

DialFunc is the type of function measured can wrap

type Measured

type Measured struct {
	// contains filtered or unexported fields

Measured is the controller to report statistics

func New

func New(maxBufferSize int) *Measured

New creates a new Measured instance

func (*Measured) Dialer

func (m *Measured) Dialer(d DialFunc, interval time.Duration) DialFunc

Dialer wraps a dial function to measure various statistics

func (*Measured) Listener

func (m *Measured) Listener(l net.Listener, interval time.Duration) *MeasuredListener

Listener wraps a listener to measure various statistics of each connection it accepts

func (*Measured) Start

func (m *Measured) Start(reportInterval time.Duration, reporters ...Reporter)

Start runs a new or stopped measured loop Reporting interval should be same for all reporters, as cached data should be cleared after each round.

func (*Measured) Stop

func (m *Measured) Stop()

Stop stops the measured loop

type MeasuredListener

type MeasuredListener struct {
	// contains filtered or unexported fields

func (*MeasuredListener) Accept

func (l *MeasuredListener) Accept() (c net.Conn, err error)

Accept wraps the same function of net.Listener to return a connection which measures various statistics

type Reporter

type Reporter interface {
	ReportTraffic(map[string]*TrafficTracker) error

Reporter encapsulates different ways to report statistics

type Traffic

type Traffic struct {
	ID       string
	BytesIn  uint64
	BytesOut uint64

Traffic encapsulates the traffic data to report

type TrafficTracker

type TrafficTracker struct {
	MinIn uint64
	MaxIn uint64
	// Temporarily disabling percentiles since we're not using them. Should we
	// need them, we could use a streaming algorithm to compute them, like this:
	//Percent95In  uint64
	LastIn  uint64
	TotalIn uint64
	MinOut  uint64
	MaxOut  uint64
	//Percent95Out uint64
	LastOut  uint64
	TotalOut uint64

TrafficTracker tracks traffic in single reporting period

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL