-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathgenerators.go
52 lines (46 loc) · 1.24 KB
/
generators.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
package test
import (
"fmt"
"math/rand"
"time"
"github.com/influxdata/influxdb-client-go/v2/api/write"
)
// GenPoints generates num points
func GenPoints(num int) []*write.Point {
points := make([]*write.Point, num)
t := time.Now()
for i := 0; i < len(points); i++ {
points[i] = write.NewPoint(
"test",
map[string]string{
"id": fmt.Sprintf("rack_%v", i%10),
"vendor": "AWS",
"hostname": fmt.Sprintf("host_%v", i%100),
},
map[string]interface{}{
"temperature": rand.Float64() * 80.0,
"disk_free": rand.Float64() * 1000.0,
"disk_total": (i/10 + 1) * 1000000,
"mem_total": (i/100 + 1) * 10000000,
"mem_free": rand.Uint64(),
},
t)
if i%10 == 0 {
t = t.Add(time.Second)
}
}
return points
}
// GenRecords generates num points
func GenRecords(num int) []string {
lines := make([]string, num)
t := time.Now()
for i := 0; i < len(lines); i++ {
lines[i] = fmt.Sprintf("test,id=rack_%v,vendor=AWS,hostname=host_%v temperature=%v,disk_free=%v,disk_total=%vi,mem_total=%vi,mem_free=%vu %v",
i%10, i%100, rand.Float64()*80.0, rand.Float64()*1000.0, (i/10+1)*1000000, (i/100+1)*10000000, rand.Uint64(), t.UnixNano())
if i%10 == 0 {
t = t.Add(time.Nanosecond)
}
}
return lines
}