measured

package module
v0.0.0-...-ec5307b Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: Apache-2.0 Imports: 7 Imported by: 18

README

measured

Wraps a dialer to measure the total bytes sent/received as well as rates thereof.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapListener

func WrapListener(l net.Listener, rateInterval time.Duration, onFinish func(Conn)) net.Listener

WrapListener wraps an existing listener with one that will measure accepted connections.

Types

type Conn

type Conn interface {
	net.Conn

	// Stats gets the stats over the lifetime of the connection
	Stats() *Stats

	// FirstError gets the the first unexpected error encountered during network
	// processing. If this is not nil, something went wrong.
	FirstError() error

	// Wrapped() exposes the wrapped net.Conn
	Wrapped() net.Conn
}

Conn is a wrapped net.Conn that exposes statistics about transfer data and the first error encountered during processing.

func Wrap

func Wrap(wrapped net.Conn, rateInterval time.Duration, onFinish func(Conn)) Conn

Wrap wraps a connection into a measured Conn that recalculates rates at the given interval.

type Stats

type Stats struct {
	SentTotal int
	SentMin   float64
	SentMax   float64
	SentAvg   float64
	RecvTotal int
	RecvMin   float64
	RecvMax   float64
	RecvAvg   float64
	// Duration indicates how long it has been since the connection was opened
	// (more precisely, how long it's been since it was wrapped by measured).
	Duration time.Duration
}

Stats provides statistics about total transfer and rates, all in bytes.

Jump to

Keyboard shortcuts

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