master
go 53 lines 804 Bytes
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package pinger
4
5 import "time"
6
7 type Sample struct {
8 Host string
9
10 PacketsSent int64
11 PacketsRecv int64
12
13 PacketLossPct float64
14
15 RTT RTTSummary
16 Jitter JitterSummary
17 }
18
19 type RTTSummary struct {
20 Valid bool
21
22 Min time.Duration
23 Max time.Duration
24 Avg time.Duration
25 StdDev time.Duration
26 }
27
28 func (r RTTSummary) VarianceMicrosecondsSquared() int64 {
29 if !r.Valid {
30 return 0
31 }
32
33 us := r.StdDev.Microseconds()
34 return us * us
35 }
36
37 func (r RTTSummary) VarianceMillisecondsSquared() float64 {
38 if !r.Valid {
39 return 0
40 }
41
42 ms := float64(r.StdDev) / float64(time.Millisecond)
43 return ms * ms
44 }
45
46 type JitterSummary struct {
47 InstantValid bool
48 Mean time.Duration
49
50 SmoothedValid bool
51 EWMA time.Duration
52 SMA time.Duration
53 }