Documentation ¶
Overview ¶
Package pinger provides a service for sending ICMP echo requests to numerous hosts in parallel. The results from each "Ping" issued can used to calculate min,max,avg and stdev latency and % loss.
A process should only create 1 pinger service which can be shared across multiple goroutines.
see github.com/raintank/go-pinger/ping-all for an example of how to use the service.
Index ¶
Constants ¶
const ProtocolICMP = 1 // Internet Control Message
const ProtocolIPv6ICMP = 58 // ICMP for IPv6
from "golang.org/x/net/internal/iana"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EchoRequest ¶
type EchoRequest struct { icmp.Message Destination net.IP Sent time.Time Received time.Time ID string WaitGroup *sync.WaitGroup }
An EchoRequest is a single ICMP echo request packet that will be sent. When the echoResponse is recieved, the "Received" field will be set and the Done() will be called on the WaitGroup.
func NewEchoRequest ¶
create a new EchoRequest instance.
type EchoResponse ¶
func (*EchoResponse) String ¶
func (e *EchoResponse) String() string
type PingStats ¶
PingStats are the results from sending ICMP echo requests to a host. The stats include the number of packets sent and received and the latency for every packet received.
type Pinger ¶
type Pinger struct { Counter int Debug bool sync.RWMutex // contains filtered or unexported fields }
Pinger represents a service that can be used for sending IMCP pings to hosts.
func NewPinger ¶
Creates a new Pinger service. Accepts the IP protocol to use "ipv4", "ipv6" or "all" and the number of packets to buffer in the request and response packet channels. The pinger instance will immediately start listening on the raw sockets (ipv4:icmp, ipv6:ipv6-icmp or both).
func (*Pinger) Ping ¶
Send <count> icmp echo rquests to <address> and don't wait longer then <timeout> for a response. An error will be returned if the EchoRequests cant be sent. This call will block until all icmp EchoResponses are received or timeout is reached. It is safe to call this method concurrently.
func (*Pinger) Send ¶
func (p *Pinger) Send(req *EchoRequest) error