-
Notifications
You must be signed in to change notification settings - Fork 12
/
reporter_windows.go
81 lines (78 loc) · 1.96 KB
/
reporter_windows.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package iperf
import (
"fmt"
"github.com/BGrewell/go-conversions"
"github.com/BGrewell/tail"
"log"
"strconv"
"strings"
"time"
)
func (r *Reporter) runLogProcessor() {
var err error
r.tailer, err = tail.TailFile(r.LogFile, tail.Config{
Follow: true,
ReOpen: true,
Poll: true,
MustExist: true,
})
if err != nil {
log.Fatalf("failed to tail log file: %v", err)
}
for {
select {
case line := <-r.tailer.Lines:
if line == nil {
continue
}
if len(line.Text) > 5 {
id := line.Text[1:4]
stream, err := strconv.Atoi(strings.TrimSpace(id))
if err != nil {
continue
}
fields := strings.Fields(line.Text[5:])
if len(fields) >= 6 {
if fields[0] == "local" {
continue
}
timeFields := strings.Split(fields[0], "-")
start, err := strconv.ParseFloat(timeFields[0], 32)
if err != nil {
log.Printf("failed to convert start time: %s\n", err)
}
end, err := strconv.ParseFloat(timeFields[1], 32)
transferedStr := fmt.Sprintf("%s%s", fields[2], fields[3])
transferedBytes, err := conversions.StringBitRateToInt(transferedStr)
if err != nil {
log.Printf("failed to convert units: %s\n", err)
}
transferedBytes = transferedBytes / 8
rateStr := fmt.Sprintf("%s%s", fields[4], fields[5])
rate, err := conversions.StringBitRateToInt(rateStr)
if err != nil {
log.Printf("failed to convert units: %s\n", err)
}
omitted := false
if len(fields) >= 7 && fields[6] == "(omitted)" {
omitted = true
}
report := &StreamIntervalReport{
Socket: stream,
StartInterval: float32(start),
EndInterval: float32(end),
Seconds: float32(end - start),
Bytes: int(transferedBytes),
BitsPerSecond: float64(rate),
Omitted: omitted,
}
r.ReportingChannel <- report
}
}
case <-time.After(100 * time.Millisecond):
if !r.running {
return
}
}
}
}