-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
73 lines (58 loc) · 1.11 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
71
72
73
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/barryz/rmqmonitor/cron"
"github.com/barryz/rmqmonitor/falcon"
"github.com/barryz/rmqmonitor/g"
v "github.com/barryz/rmqmonitor/version"
"github.com/barryz/rmqmonitor/witch"
)
func collect() {
go metricCollector(g.Config().Interval)
}
func rotateQLog() {
go cron.Start()
}
func witchLaunch() {
go witch.Launch()
}
func metricCollector(sec int64) {
t := time.NewTicker(time.Second * time.Duration(sec)).C
for {
<-t
falcon.Collector()
}
}
func main() {
cfg := flag.String("c", "cfg.json", "configuration file")
ver := flag.Bool("v", false, "show agent version")
flag.Parse()
if *ver {
fmt.Println(v.Build)
os.Exit(0)
}
g.ParseConfig(*cfg)
if g.Config().Enabled.Collect {
collect()
}
if g.Config().Enabled.LogRotate {
rotateQLog()
}
if g.Config().Enabled.Witch {
witchLaunch()
}
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
sig := <-signals
log.Printf("Signal %v captured", sig)
os.Exit(0)
}()
select {}
}