-
Notifications
You must be signed in to change notification settings - Fork 113
/
devops_net.go
72 lines (59 loc) · 1.94 KB
/
devops_net.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
package devops
import (
"fmt"
. "github.com/influxdata/influxdb-comparisons/bulk_data_gen/common"
"math/rand"
"time"
)
var (
NetByteString = []byte("net") // heap optimization
NetTags = [][]byte{
[]byte("interface"),
}
NetFields = []LabeledDistributionMaker{
{[]byte("bytes_sent"), func() Distribution { return MWD(ND(50, 1), 0) }},
{[]byte("bytes_recv"), func() Distribution { return MWD(ND(50, 1), 0) }},
{[]byte("packets_sent"), func() Distribution { return MWD(ND(50, 1), 0) }},
{[]byte("packets_recv"), func() Distribution { return MWD(ND(50, 1), 0) }},
{[]byte("err_in"), func() Distribution { return MWD(ND(5, 1), 0) }},
{[]byte("err_out"), func() Distribution { return MWD(ND(5, 1), 0) }},
{[]byte("drop_in"), func() Distribution { return MWD(ND(5, 1), 0) }},
{[]byte("drop_out"), func() Distribution { return MWD(ND(5, 1), 0) }},
}
)
type NetMeasurement struct {
timestamp time.Time
interfaceName []byte
uptime time.Duration
distributions []Distribution
}
func NewNetMeasurement(start time.Time) *NetMeasurement {
distributions := make([]Distribution, len(NetFields))
for i := range NetFields {
distributions[i] = NetFields[i].DistributionMaker()
}
interfaceName := []byte(fmt.Sprintf("eth%d", rand.Intn(4)))
if Config != nil { // partial override from external config
interfaceName = Config.GetTagBytesValue(NetByteString, NetTags[0], true, interfaceName)
}
return &NetMeasurement{
interfaceName: interfaceName,
timestamp: start,
distributions: distributions,
}
}
func (m *NetMeasurement) Tick(d time.Duration) {
m.timestamp = m.timestamp.Add(d)
for i := range m.distributions {
m.distributions[i].Advance()
}
}
func (m *NetMeasurement) ToPoint(p *Point) bool {
p.SetMeasurementName(NetByteString)
p.SetTimestamp(&m.timestamp)
p.AppendTag(NetTags[0], m.interfaceName)
for i := range m.distributions {
p.AppendField(NetFields[i].Label, int64(m.distributions[i].Get()))
}
return true
}