Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Linux ¶
type Linux struct{}
Linux implements the Ping interface for Linux.
func NewLinuxProvider ¶
func NewLinuxProvider() *Linux
NewLinuxProvider factory to create a new Linux instance.
type Pinger ¶
type Pinger interface { // SetPrivileged sets whether the pinger will run in privileged mode (using raw sockets). // This may require elevated privileges or specific system configurations to work. SetPrivileged(privileged bool) // Run initiates the ping operation. This method blocks until the operation is completed. Run() error // Statistics returns the results of the ping operation, including packet loss, RTT, and other metrics. Statistics() *probing.Statistics // SetCount specifies the number of ping packets to send. A value of 3 means the ping will attempt 3 times. SetCount(count int) }
Pinger is the interface representing the pinging functionality.
type PingerWrapper ¶
PingerWrapper wrapper struct around probing.Pinger.
func (*PingerWrapper) SetCount ¶
func (p *PingerWrapper) SetCount(count int)
SetCount sets the count of pings to be sent.
type Provider ¶
type Provider interface { // Do pings the given host and returns the ping statistics or an error. Do(address string) (*Result, error) }
Provider implements the methods to interact with various ping components.
type Result ¶
type Result struct { // Number of packets sent PacketsSent int // Number of packets received PacketsReceived int // Percentage of packet loss PacketLoss float64 // Minimum round-trip time MinRTT time.Duration // Average round-trip time AvgRTT time.Duration // Maximum round-trip time MaxRTT time.Duration }
Result represents custom ping result details.
type Ubuntu ¶
Ubuntu implements the Ping interface for Ubuntu.
func NewUbuntuProvider ¶
func NewUbuntuProvider() *Ubuntu
NewUbuntuProvider factory to create a new Ubuntu instance.
func (*Ubuntu) Do ¶
Do pings the given host and returns the ping statistics or an error. It returns a Result struct, and an error if something goes wrong.
On Linux, it attempts an "unprivileged" ping via UDP by default. To enable unprivileged pings, run the following command:
sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
Alternatively, call pinger.SetPrivileged(true) to use raw sockets. After doing so, you may either:
- Run the binary as root, or
- Set capabilities on the binary to allow raw socket usage: sudo setcap cap_net_raw=+ep /path/to/your/compiled/binary