ping

package
v4.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const KillGrace = 5 * time.Second

KillGrace is the amount of time we allow a process to shutdown before sending a SIGKILL.

Variables

View Source
var ErrTimeout = errors.New("command timed out")

Functions

func CombinedOutputTimeout

func CombinedOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error)

CombinedOutputTimeout runs the given command with the given timeout and returns the combined output of stdout and stderr. If the command times out, it attempts to kill the process.

func MyHostPinger

func MyHostPinger(binary string, timeout float64, args ...string) (string, error)

func RunTimeout

func RunTimeout(c *exec.Cmd, timeout time.Duration) error

RunTimeout runs the given command with the given timeout. If the command times out, it attempts to kill the process.

func StdOutputTimeout

func StdOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error)

StdOutputTimeout runs the given command with the given timeout and returns the output of stdout. If the command times out, it attempts to kill the process.

func WaitTimeout

func WaitTimeout(c *exec.Cmd, timeout time.Duration) error

WaitTimeout waits for the given command to finish with a timeout. It assumes the command has already been started. If the command times out, it attempts to kill the process.

Types

type HostPinger

type HostPinger func(binary string, timeout float64, args ...string) (string, error)

HostPinger is a function that runs the "ping" function using a list of passed arguments. This can be easily switched with a mocked ping function for unit test purposes (see ping_test.go)

type NativePingFunc

type NativePingFunc func(destination string) (*pingStats, error)

type Ping

type Ping struct {
	Log telegraf.Logger `toml:"-"`

	// Interval at which to ping (ping -i <INTERVAL>)
	PingInterval float64 `toml:"ping_interval"`

	// Number of pings to send (ping -c <COUNT>)
	Count int

	// Per-ping timeout, in seconds. 0 means no timeout (ping -W <TIMEOUT>)
	Timeout float64

	// Ping deadline, in seconds. 0 means no deadline. (ping -w <DEADLINE>)
	Deadline int

	// Interface or source address to send ping from (ping -I/-S <INTERFACE/SRC_ADDR>)
	Interface string

	// URLs to ping
	Urls []string

	// Method defines how to ping (native or exec)
	Method string

	// Ping executable binary
	Binary string

	// Arguments for ping command. When arguments is not empty, system binary will be used and
	// other options (ping_interval, timeout, etc) will be ignored
	Arguments []string

	// Whether to resolve addresses using ipv6 or not.
	IPv6 bool

	// host ping function
	PingHost HostPinger

	NativePingFunc NativePingFunc

	// Calculate the given percentiles when using native method
	Percentiles []int
	// contains filtered or unexported fields
}

func (*Ping) Description

func (*Ping) Description() string

func (*Ping) Gather

func (p *Ping) Gather(acc telegraf.Accumulator) error

func (*Ping) Init

func (p *Ping) Init() error

Init ensures the plugin is configured correctly.

func (*Ping) NativePing

func (p *Ping) NativePing(destination string) (*pingStats, error)

func (*Ping) SampleConfig

func (*Ping) SampleConfig() string

Jump to

Keyboard shortcuts

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