monitor

package
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type History

type History struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

History represents the ping history for a single node/device.

func NewHistory

func NewHistory(capacity int) History

NewHistory creates a new History object with a specific capacity.

func (*History) AddResult

func (h *History) AddResult(rtt time.Duration, err error)

AddResult saves a ping result into the internal history.

func (*History) Compute

func (h *History) Compute() *Metrics

Compute aggregates the result history into a single data point.

func (*History) ComputeAndClear

func (h *History) ComputeAndClear() *Metrics

ComputeAndClear aggregates the result history into a single data point and clears the result set.

type Metrics

type Metrics struct {
	PacketsSent int           // number of packets sent
	PacketsLost int           // number of packets lost
	Best        time.Duration // best rtt
	Worst       time.Duration // worst rtt
	Median      time.Duration // median rtt
	Mean        time.Duration // mean rtt
	StdDev      time.Duration // std deviation
}

Metrics is a dumb data point computed from a history of Results.

type Monitor

type Monitor struct {
	HistorySize int // Number of results per target to keep
	PayloadSize uint16
	Privileged  bool
	// contains filtered or unexported fields
}

Monitor manages the goroutines responsible for collecting Ping RTT data.

func New

func New(interval time.Duration) *Monitor

New creates and configures a new Ping instance. You need to call AddTarget()/RemoveTarget() to manage monitored targets.

func (*Monitor) AddTarget

func (m *Monitor) AddTarget(key string, addr net.IPAddr)

AddTarget adds a target to the monitored list. If the target with the given ID already exists, it is removed first and then readded. This allows the easy restart of the monitoring.

func (*Monitor) Export

func (m *Monitor) Export() map[string]*Metrics

Export calculates the metrics for each monitored target and returns it as a simple map.

func (*Monitor) RemoveTarget

func (m *Monitor) RemoveTarget(key string)

RemoveTarget removes a target from the monitoring list.

func (*Monitor) Start

func (m *Monitor) Start(bind4, bind6 string) error

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop brings the monitoring gracefully to a halt.

type Result

type Result struct {
	RTT  time.Duration
	Lost bool
}

Result stores the information about a single ping, in particular the round-trip time or whether the packet was lost.

Jump to

Keyboard shortcuts

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