-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (63 loc) · 1.92 KB
/
main.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 main
import (
"flag"
"github.com/antonsoroko/statsd-router/statsdrouter"
"log"
"os"
"os/signal"
"syscall"
)
var (
configFile = flag.String("config", "statsd-router.json", "Configuration file path")
bindAddress = flag.String("bind-address", "0.0.0.0", "Address to bind")
port = flag.Uint("port", 48125, "Port to use")
apiPort = flag.Uint("api-port", 48126, "Port for API to use")
masterHostString = flag.String("master-statsd-host", "localhost:8125:8126", "Host that will receive all metrics. Format is host:port:mgmt_port")
checkInterval = flag.Int64("check-interval", 180, "Interval of checking for backend health")
debug = flag.Bool("debug", false, "Enable debug mode")
printStats = flag.Bool("print-stats", false, "Enable printing internal statistics to the console")
)
func main() {
flag.Parse()
masterHost, err := statsdrouter.NewStatsdNode(*masterHostString)
if err != nil {
log.Fatalf("Failed to convert master-statsd-host to StatsdNode: %s", err)
}
log.Printf("Using %+v as master host", masterHost)
statsdrouter.DebugMode = *debug
statsdrouter.PrintStats = *printStats
quit := make(chan bool)
handleSignals(quit)
statsdrouter.StartRouter(
*bindAddress,
uint16(*port),
uint16(*apiPort),
masterHost,
*configFile,
*checkInterval,
quit,
)
log.Println("Exit.")
}
func handleSignals(quit chan bool) {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
go func(chan os.Signal) {
defer signal.Reset()
defer signal.Stop(sigs)
loop:
for sig := range sigs {
log.Printf("caught signal: %+v", sig)
switch sig {
case os.Interrupt, syscall.SIGTERM:
log.Println("Sending quit signal to goroutines...")
close(quit)
break loop
case syscall.SIGHUP:
// TODO: implement real reloading?
log.Println("Reloading...")
}
log.Println("Terminating Signals Handler.")
}
}(sigs)
}