-
Notifications
You must be signed in to change notification settings - Fork 1
/
Packets.go
55 lines (45 loc) · 1.08 KB
/
Packets.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
package flows
import (
"analysis/flows"
)
type MetricPackets struct{}
func newMetricPackets() *MetricPackets {
return &MetricPackets{}
}
func (mp *MetricPackets) calc(flow *flows.Flow) ValuePackets {
var numPackets, numPacketsClient, numPacketsServer uint32
packets := flow.Packets
for i := 0; i < len(packets); i++ {
p := packets[i]
numPackets++
if p.FromClient {
numPacketsClient++
} else {
numPacketsServer++
}
}
return ValuePackets{
packets: numPackets,
packetsServer: numPacketsServer,
packetsClient: numPacketsClient,
}
}
func (mp *MetricPackets) onFlush(flow *flows.Flow) ExportableValue {
value := mp.calc(flow)
return value
}
type ValuePackets struct {
// The number of packets that were exchanged.
packets uint32
// The number of packets the client sent.
packetsClient uint32
// Port number of packets the server sent.
packetsServer uint32
}
func (vp ValuePackets) export() map[string]interface{} {
return map[string]interface{}{
"packets": vp.packets,
"packetsClient": vp.packetsClient,
"packetsServer": vp.packetsServer,
}
}