forked from timescale/tsbs
-
Notifications
You must be signed in to change notification settings - Fork 6
/
generate_data.go
77 lines (62 loc) · 2.02 KB
/
generate_data.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
package devops
import (
"time"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/common"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/serialize"
)
// DevopsSimulator generates data similar to telemetry, with metrics from a variety of device systems.
// It fulfills the Simulator interface.
type DevopsSimulator struct {
*commonDevopsSimulator
simulatedMeasurementIndex int
}
// Next advances a Point to the next state in the generator.
func (d *DevopsSimulator) Next(p *serialize.Point) bool {
// switch to the next metric if needed
if d.hostIndex == uint64(len(d.hosts)) {
d.hostIndex = 0
d.simulatedMeasurementIndex++
}
if d.simulatedMeasurementIndex == len(d.hosts[0].SimulatedMeasurements) {
d.simulatedMeasurementIndex = 0
for i := 0; i < len(d.hosts); i++ {
d.hosts[i].TickAll(d.interval)
}
d.adjustNumHostsForEpoch()
}
return d.populatePoint(p, d.simulatedMeasurementIndex)
}
// DevopsSimulatorConfig is used to create a DevopsSimulator.
type DevopsSimulatorConfig struct {
Start time.Time
End time.Time
InitHostCount uint64
HostCount uint64
HostConstructor func(i int, start time.Time) Host
}
// ToSimulator produces a Simulator that conforms to the given SimulatorConfig over the specified interval
func (d *DevopsSimulatorConfig) ToSimulator(interval time.Duration) common.Simulator {
hostInfos := make([]Host, d.HostCount)
for i := 0; i < len(hostInfos); i++ {
hostInfos[i] = d.HostConstructor(i, d.Start)
}
epochs := uint64(d.End.Sub(d.Start).Nanoseconds() / interval.Nanoseconds())
maxPoints := epochs * d.HostCount * uint64(len(hostInfos[0].SimulatedMeasurements))
dg := &DevopsSimulator{
commonDevopsSimulator: &commonDevopsSimulator{
madePoints: 0,
maxPoints: maxPoints,
hostIndex: 0,
hosts: hostInfos,
epoch: 0,
epochs: epochs,
epochHosts: d.InitHostCount,
initHosts: d.InitHostCount,
timestampStart: d.Start,
timestampEnd: d.End,
interval: interval,
},
simulatedMeasurementIndex: 0,
}
return dg
}