forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
73 lines (63 loc) · 1.48 KB
/
client.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
package main
import (
"collectd.org/api"
"collectd.org/network"
"context"
"flag"
"fmt"
"math/rand"
"os"
"strconv"
"time"
)
var nMeasurments = flag.Int("m", 1, "Number of measurements")
var tagVariance = flag.Int("v", 1, "Number of values per tag. Client is fixed at one tag")
var rate = flag.Int("r", 1, "Number of points per second")
var total = flag.Int("t", -1, "Total number of points to send (default is no limit)")
var host = flag.String("u", "127.0.0.1:25826", "Destination host in the form host:port")
func main() {
flag.Parse()
conn, err := network.Dial(*host, network.ClientOptions{})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer conn.Close()
rateLimiter := make(chan int, *rate)
go func() {
ticker := time.NewTicker(time.Second)
for {
select {
case <-ticker.C:
for i := 0; i < *rate; i++ {
rateLimiter <- i
}
}
}
}()
nSent := 0
for {
if nSent >= *total && *total > 0 {
break
}
<-rateLimiter
vl := api.ValueList{
Identifier: api.Identifier{
Host: "tagvalue" + strconv.Itoa(int(rand.Int31n(int32(*tagVariance)))),
Plugin: "golang" + strconv.Itoa(int(rand.Int31n(int32(*nMeasurments)))),
Type: "gauge",
},
Time: time.Now(),
Interval: 10 * time.Second,
Values: []api.Value{api.Gauge(42.0)},
}
ctx := context.TODO()
if err := conn.Write(ctx, &vl); err != nil {
fmt.Println(err)
os.Exit(1)
}
conn.Flush()
nSent = nSent + 1
}
fmt.Println("Number of points sent:", nSent)
}