pinger

package
v0.0.0-...-f83b936 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout to be used to a ping request.
	DefaultTimeout = time.Second

	// DefaultPacketSize is the default packet size for ping requests.
	DefaultPacketSize = uint(56)
)

Variables

This section is empty.

Functions

func Resolve

func Resolve(host string) (net.Addr, error)

Resolve resolves the given host to a net.Addr.

Types

type Options

type Options struct {
	// Timeout sets the timeout for each ping request.
	// The default timeout is 1 second.
	Timeout time.Duration

	// Count sets the number of packets to be sent/received.
	// The default count is 0, which means ping requests will be sent
	// indefinitely.
	Count uint

	// PacketSize sets the size of packets to be sent/received.
	// The default packet size is 56 bytes.
	PacketSize uint
}

Options defines the options for a Pinger.

type Ping

type Ping struct {
	// Seq is the sequence number.
	Seq int

	// Size is the number of bytes in the response.
	Size int

	// RTT is the duration for the round trip.
	RTT time.Duration

	// Timeout is whether or not the request timed out.
	Timeout bool
}

Ping represents a ping request/response.

type Pinger

type Pinger interface {
	// Ping accepts a net.Addr representing a host and sends ICMP ping packets
	// to that host. Ping is a blocking operation.
	Ping(addr net.Addr)

	// Stop signals the Pinger to stop sending ping requests to the host.
	// After a call to Stop(), Ping() is expected to return.
	Stop()

	// Report returns the pair of channels where results will be reported to:
	// 1) a channel of type Ping for successful requests (including temporary errors, e.g. timeouts)
	// 2) a channel of type error for unrecoverable errors
	Report() (<-chan Ping, <-chan error)

	// Stats returns the packet statistics accumulated for the host being
	// pinged.
	Stats() Stats
}

Pinger defines the operations of a pinger.

func NewPinger

func NewPinger(opts *Options) Pinger

NewPinger accepts an Options object and returns a new Pinger configured with the given options.

type Stats

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

Stats stores the packet statistics.

func (*Stats) PacketLoss

func (s *Stats) PacketLoss() float64

PacketLoss calculates and returns the percentage of packets that have been lost (i.e. a packet was sent, but a reply was not received due to a timeout).

func (*Stats) RTTStats

func (s *Stats) RTTStats() (float64, float64, float64, float64)

RTTStats calculates and returns, respectively, the min, average, max and standard deviation for round-trip latencies.

func (*Stats) Received

func (s *Stats) Received() int

Received returns the total number of packets successfully received back.

func (*Stats) Transmitted

func (s *Stats) Transmitted() int

Transmitted returns the total number of packets transmitted.

Jump to

Keyboard shortcuts

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