probeutils

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package probeutils implements utilities that are shared across multiple probe types.

Index

Constants

This section is empty.

Variables

View Source
var InterfaceByName = func(s string) (Addr, error) { return net.InterfaceByName(s) }

InterfaceByName is a mocking point for net.InterfaceByName, used for tests.

Functions

func IPVersion added in v0.10.3

func IPVersion(ip net.IP) int

IPVersion tells if an IP address is IPv4 or IPv6.

func PatternPayload

func PatternPayload(payload, pattern []byte)

PatternPayload builds a payload that can be verified using VerifyPayloadPattern. It repeats the pattern to fill the payload []byte slice. Last remaining bytes (len(payload) mod patternSize) are left unpopulated (hence set to 0 bytes).

func ResolveIntfAddr

func ResolveIntfAddr(intfName string, ipVer int) (net.IP, error)

ResolveIntfAddr takes the name of a network interface and IP version, and returns the first IP address of the interface that matches the specified IP version. If no IP version is specified (ipVer is 0), simply the first IP address is returned.

func StatsKeeper

func StatsKeeper(ctx context.Context, ptype, name string, exportInterval time.Duration, targetsFunc func() []string, resultsChan <-chan ProbeResult, dataChan chan<- *metrics.EventMetrics, logMetrics func(*metrics.EventMetrics), l *logger.Logger)

StatsKeeper manages and outputs probe results.

Typical StatsKeepr usage pattern is that the probes start a StatsKeeper goroutine in the beginning. StatsKeeper goroutine manages access to the per-target cumulative metrics. It listens on an input channel for probe results and updates the metrics whenever a new probe result is obtained. It exports aggregate probe statistics to the output channel, at intervals controlled by a Ticker. These two operations are mutually exclusive. This is the only goroutine that accesses the metrics. StatsKeeper runs indefinitely, across multiple probe runs, and should not stop during normal program execution.

If we get a new result on resultsChan, update the probe statistics. If we get a timer tick on doExport, export probe data for all targets. If context is canceled, return.

Note that StatsKeeper calls a function (targetsFunc) to get the list of the targets for exporting results, instead of getting a static list in the arguments. We do that as the list of targets is usually dynamic and is updated on a regular basis.

func VerifyPayloadPattern

func VerifyPayloadPattern(payload, pattern []byte) error

VerifyPayloadPattern verifies the payload built using PatternPayload.

Types

type Addr

type Addr interface {
	Addrs() ([]net.Addr, error)
}

Addr is used for tests, allowing net.InterfaceByName to be mocked.

type ProbeResult

type ProbeResult interface {
	// Metrics converts ProbeResult into a map of the metrics that is suitable for
	// working with metrics.EventMetrics.
	Metrics() *metrics.EventMetrics

	// Target returns the target associated with the probe result.
	Target() string
}

ProbeResult represents results of a probe run.

Jump to

Keyboard shortcuts

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