-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjerks.go
More file actions
56 lines (47 loc) · 1001 Bytes
/
jerks.go
File metadata and controls
56 lines (47 loc) · 1001 Bytes
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
package main
import (
"flag"
"log"
"math/rand"
"os"
"os/signal"
"runtime"
"strconv"
"syscall"
"github.com/juju/ratelimit"
"github.com/rodaine/statstee/datagram"
)
var (
num = 1
rps int64 = 1000
)
func init() {
flag.IntVar(&num, "n", num, "number of different metrics to generate")
flag.Int64Var(&rps, "r", rps, "the metrics per second to send")
flag.Parse()
}
func main() {
limiter := ratelimit.NewBucketWithRate(float64(rps), rps)
for n := runtime.NumCPU(); n >= 0; n-- {
go beAJerk(limiter)
}
waitForSignal()
}
func beAJerk(limiter *ratelimit.Bucket) {
sender, _ := datagram.NewSender("localhost", 8125)
for {
limiter.Wait(1)
sender.Send(datagram.Metric{
Type: datagram.Histogram,
Name: "jerks." + strconv.Itoa(rand.Intn(num)),
Value: rand.Float64(),
SampleRate: 1,
})
}
}
func waitForSignal() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
<-c
log.Println("kill signal received")
}