-
Notifications
You must be signed in to change notification settings - Fork 1
/
Duration.go
46 lines (37 loc) · 895 Bytes
/
Duration.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
package flows
import (
"analysis/flows"
)
type MetricFlowDuration struct{}
func newMetricFlowDuration() *MetricFlowDuration {
return &MetricFlowDuration{}
}
func (mfd *MetricFlowDuration) calc(flow *flows.Flow) ValueFlowDuration {
packets := flow.Packets
start := packets[0].Timestamp
end := packets[len(packets)-1].Timestamp
return ValueFlowDuration{
start: start,
end: end,
duration: end - start,
}
}
func (mfd *MetricFlowDuration) onFlush(flow *flows.Flow) ExportableValue {
value := mfd.calc(flow)
return value
}
type ValueFlowDuration struct {
// Start time as unix timestamp.
start int64
// End time as unix timestamp.
end int64
// Duration in nano seconds.
duration int64
}
func (vfd ValueFlowDuration) export() map[string]interface{} {
return map[string]interface{}{
"start": vfd.start,
"end": vfd.end,
"duration": vfd.duration,
}
}