forked from nightlyworker/dd_rethinkdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dd_rethinkdb.go
72 lines (60 loc) · 1.29 KB
/
dd_rethinkdb.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
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"
log "github.com/Sirupsen/logrus"
)
var (
env = os.Getenv("DD_RETHINKDB_ENV")
addr = flag.String("addr", "localhost:28015", "Database cluster address, comma separated")
tags = flag.String("tags", "rethinkdb", "Tags to associate with metrics, comma separated")
tick = flag.Duration("tick", 15*time.Second, "Statistics check interval")
verbose = flag.Bool("verbose", false, "Enable verbose logging")
)
func init() {
if env == "" || env == "dev" {
log.SetFormatter(&log.TextFormatter{})
} else {
log.SetFormatter(&log.JSONFormatter{})
}
flag.Usage = func() {
fmt.Println(NameVersion())
fmt.Println()
fmt.Println("usage: dd_rethinkdb [options]")
fmt.Println()
fmt.Println("options:")
flag.PrintDefaults()
os.Exit(0)
}
}
func main() {
flag.Parse()
if len(*addr) == 0 {
flag.Usage()
}
log.Println(NameVersion())
sigs := make(chan os.Signal)
done := make(chan bool)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
done <- true
}()
stats := NewRethinkStats(*addr, *tags, env, *verbose)
stats.Query()
ticker := time.NewTicker(*tick)
for {
select {
case <-ticker.C:
stats.Query()
case <-done:
ticker.Stop()
stats.Close()
return
}
}
}