-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
64 lines (57 loc) · 1.38 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"strings"
)
type mtrRoot struct {
Source string `json:"src"`
Destination string `json:"dst"`
TypeOfService string `json:"tos"`
PatternSize string `json:"psize"`
BitPattern string `json:"bitpattern"`
NumberOfTests string `json:"tests"`
}
type mtrHub struct {
Count string `json:"count"`
Host string `json:"host"`
LossPercent float32 `json:"Loss%"`
Sent int `json:"Snt"`
Last float32 `json:"Last"`
Average float32 `json:"Avg"`
Best float32 `json:"Best"`
Worst float32 `json:"Wrst"`
StandardDeviation float32 `json:"StDev"`
}
func (h mtrHub) String() string {
return fmt.Sprintf(
"destination=%s,hop=%s sent=%d,loss=%f,last=%f,best=%f,worst=%f,avg=%f,stddev=%f",
h.Host,
h.Count,
h.Sent,
h.LossPercent,
h.Last,
h.Best,
h.Worst,
h.Average,
h.StandardDeviation,
)
}
type mtrReport struct {
MTR mtrRoot `json:"mtr"`
Hubs []mtrHub `json:"hubs"`
Timestamp int64 `json:"timestamp"`
}
func (r mtrReport) String() string {
var (
lines []string
measure = r.MTR.Destination
timestamp = r.Timestamp
)
for _, hub := range r.Hubs {
lines = append(lines, fmt.Sprintf("%s,%s %d", measure, hub.String(), timestamp))
}
return strings.Join(lines, "\n")
}
type mtrResult struct {
Report mtrReport `json:"report"`
}