monitor

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 6 Imported by: 11

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        float32 // best rtt in ms
	Worst       float32 // worst rtt in ms
	Median      float32 // median rtt in ms
	Mean        float32 // mean rtt in ms
	StdDev      float32 // std deviation in ms
}

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
	// contains filtered or unexported fields
}

Monitor manages the goroutines responsible for collecting Ping RTT data.

func New

func New(pinger *ping.Pinger, interval, timeout 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 (p *Monitor) AddTarget(key string, addr net.IPAddr) (err error)

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) AddTargetDelayed

func (p *Monitor) AddTargetDelayed(key string, addr net.IPAddr, startupDelay time.Duration) (err error)

AddTargetDelayed is AddTarget with a startup delay

func (*Monitor) Export

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

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

func (*Monitor) ExportAndClear

func (p *Monitor) ExportAndClear() map[string]*Metrics

ExportAndClear calculates the metrics for each monitored target, cleans the result set and returns it as a simple map.

func (*Monitor) RemoveTarget

func (p *Monitor) RemoveTarget(key string)

RemoveTarget removes a target from the monitoring list.

func (*Monitor) Stop

func (p *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.

type Target

type Target struct {
	// contains filtered or unexported fields
}

Target is a unit of work

func (*Target) Compute

func (n *Target) Compute(clear bool) *Metrics

Compute returns the computed ping metrics for this node and optonally clears the result set.

func (*Target) Stop

func (n *Target) Stop()

Stop gracefully stops the monitoring.

Jump to

Keyboard shortcuts

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