-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu_only_generate_data.go
70 lines (56 loc) · 1.86 KB
/
cpu_only_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
package devops
import (
"time"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/common"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/serialize"
)
// A CPUOnlySimulator generates data similar to telemetry from Telegraf for only CPU metrics.
// It fulfills the Simulator interface.
type CPUOnlySimulator struct {
*commonDevopsSimulator
}
// Fields returns a map of subsystems to metrics collected
func (d *CPUOnlySimulator) Fields() map[string][][]byte {
return d.fields(d.hosts[0].SimulatedMeasurements[:1])
}
// Next advances a Point to the next state in the generator.
func (d *CPUOnlySimulator) Next(p *serialize.Point) bool {
// Switch to the next metric if needed
if d.hostIndex == uint64(len(d.hosts)) {
d.hostIndex = 0
for i := 0; i < len(d.hosts); i++ {
d.hosts[i].TickAll(d.interval)
}
d.adjustNumHostsForEpoch()
}
return d.populatePoint(p, 0)
}
// CPUOnlySimulatorConfig is used to create a CPUOnlySimulator.
type CPUOnlySimulatorConfig commonDevopsSimulatorConfig
// NewSimulator produces a Simulator that conforms to the given SimulatorConfig over the specified interval
func (c *CPUOnlySimulatorConfig) NewSimulator(interval time.Duration, limit uint64) common.Simulator {
hostInfos := make([]Host, c.HostCount)
for i := 0; i < len(hostInfos); i++ {
hostInfos[i] = c.HostConstructor(i, c.Start)
}
epochs := calculateEpochs(commonDevopsSimulatorConfig(*c), interval)
maxPoints := epochs * c.HostCount
if limit > 0 && limit < maxPoints {
// Set specified points number limit
maxPoints = limit
}
sim := &CPUOnlySimulator{&commonDevopsSimulator{
madePoints: 0,
maxPoints: maxPoints,
hostIndex: 0,
hosts: hostInfos,
epoch: 0,
epochs: epochs,
epochHosts: c.InitHostCount,
initHosts: c.InitHostCount,
timestampStart: c.Start,
timestampEnd: c.End,
interval: interval,
}}
return sim
}