-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
59 lines (53 loc) · 1.12 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
package main
import (
"flag"
"github.com/dubuqingfeng/api-monitor/dbs"
"github.com/dubuqingfeng/api-monitor/fetchers"
"github.com/dubuqingfeng/api-monitor/processors"
"github.com/dubuqingfeng/api-monitor/utils"
"github.com/robfig/cron/v3"
log "github.com/sirupsen/logrus"
"net/http"
_ "net/http/pprof"
"time"
)
func init() {
utils.InitConfig("./configs/config.yaml")
log.Info(utils.Config)
utils.ConfigLocalFileSystemLogger("./logs/", "monitor.log", 7*time.Hour*24, time.Second*20)
dbs.InitMySQLDB()
processors.InitRulerLoader()
}
func main() {
mode := flag.String("mode", "cron", "")
flag.Parse()
SetProfiling()
if *mode == "command" {
RunCommand()
} else {
StartCronJobs()
}
}
func SetProfiling() {
if utils.Config.IsDebug {
go func() {
if err := http.ListenAndServe("0.0.0.0:6060", nil); err != nil {
log.Error(err)
}
}()
}
}
func RunCommand() {
fetch := fetchers.NewAPIFetcher()
fetch.Handle()
}
func StartCronJobs() {
c := cron.New()
_, err := c.AddFunc(utils.GetMonitoringExpression(), func() { RunCommand() })
if err != nil {
log.Error(err)
}
c.Start()
defer c.Stop()
select {}
}