forked from Super-long/influxdb-comparisons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.go
117 lines (100 loc) · 4.04 KB
/
host.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package dashboard
import (
"fmt"
. "github.com/antondavidsen/influxdb-comparisons/bulk_data_gen/common"
"github.com/antondavidsen/influxdb-comparisons/bulk_data_gen/devops"
"math/rand"
"time"
)
const NHostSims = 11
var ClusterSizes = []int{5, 6, 7, 8, 9, 10, 11, 12, 13}
var ClusterSize = 10
var ClusterIdTagkey = []byte("cluster_id")
// Type Host models a machine being monitored by Telegraf.
type Host struct {
SimulatedMeasurements []SimulatedMeasurement
// These are all assigned once, at Host creation:
Name, Region, Datacenter, Rack, OS, Arch []byte
ClusterId, Service, ServiceVersion, ServiceEnvironment []byte
}
func NewHostMeasurements(start time.Time) []SimulatedMeasurement {
sm := []SimulatedMeasurement{
devops.NewCPUMeasurement(start),
devops.NewDiskIOMeasurement(start),
devops.NewDiskMeasurement(start, 1),
devops.NewKernelMeasurement(start),
devops.NewMemMeasurement(start),
devops.NewNetMeasurement(start),
devops.NewNginxMeasurement(start),
devops.NewPostgresqlMeasurement(start),
devops.NewRedisMeasurement(start),
NewSystemMeasurement(start),
NewStatusMeasurement(start),
}
if len(sm) != NHostSims {
panic("logic error: incorrect number of measurements")
}
return sm
}
var (
currentClusterSize int
clusterId int
currentHostIndex int
)
func NewHost(i int, offset int, start time.Time) Host {
var hostname []byte
if i > 0 {
if currentClusterSize == 0 || currentHostIndex == currentClusterSize {
currentHostIndex = 0
currentClusterSize = ClusterSize //ClusterSizes[rand.Intn(len(ClusterSizes))]
clusterId++
}
if currentHostIndex < 3 {
hostname = []byte(fmt.Sprintf("meta_%d", currentHostIndex+1 /*+offset*/)) // hostname is 1-indexed in its cluster
} else {
hostname = []byte(fmt.Sprintf("data_%d", currentHostIndex-2 /*+offset*/)) // hostname is 1-indexed in its cluster
}
} else {
hostname = []byte(fmt.Sprintf("kapacitor_%d", 1 /*+offset*/)) // hostname is 1-indexed in its cluster
}
sm := NewHostMeasurements(start)
region := &devops.Regions[rand.Intn(len(devops.Regions))]
rackId := rand.Int63n(devops.MachineRackChoicesPerDatacenter)
serviceId := rand.Int63n(devops.MachineServiceChoices)
serviceVersionId := rand.Int63n(devops.MachineServiceVersionChoices)
serviceEnvironment := RandChoice(devops.MachineServiceEnvironmentChoices)
clusterOffset := offset / ClusterSize
h := Host{
// Tag Values that are static throughout the life of a Host:
Name: hostname,
Region: []byte(fmt.Sprintf("%s", region.Name)),
Datacenter: RandChoice(region.Datacenters),
Rack: []byte(fmt.Sprintf("%d", rackId)),
Arch: RandChoice(devops.MachineArchChoices),
OS: RandChoice(devops.MachineOSChoices),
Service: []byte(fmt.Sprintf("%d", serviceId)),
ServiceVersion: []byte(fmt.Sprintf("%d", serviceVersionId)),
ServiceEnvironment: serviceEnvironment,
ClusterId: []byte(fmt.Sprintf("%d", clusterId+clusterOffset)),
SimulatedMeasurements: sm,
}
// partial override from external config
if Config != nil {
h.Region = Config.GetTagBytesValue(nil, devops.MachineTagKeys[1], true, []byte(h.Region))
h.Datacenter = Config.GetTagBytesValue(nil, devops.MachineTagKeys[2], true, []byte(h.Datacenter))
h.Rack = Config.GetTagBytesValue(nil, devops.MachineTagKeys[3], true, []byte(h.Rack))
h.OS = Config.GetTagBytesValue(nil, devops.MachineTagKeys[4], true, []byte(h.OS))
h.Arch = Config.GetTagBytesValue(nil, devops.MachineTagKeys[5], true, []byte(h.Arch))
h.Service = Config.GetTagBytesValue(nil, devops.MachineTagKeys[7], true, []byte(h.Service))
h.ServiceVersion = Config.GetTagBytesValue(nil, devops.MachineTagKeys[8], true, []byte(h.ServiceVersion))
h.ServiceEnvironment = Config.GetTagBytesValue(nil, devops.MachineTagKeys[9], true, []byte(h.ServiceEnvironment))
}
currentHostIndex++
return h
}
// TickAll advances all Distributions of a Host.
func (h *Host) TickAll(d time.Duration) {
for i := range h.SimulatedMeasurements {
h.SimulatedMeasurements[i].Tick(d)
}
}