-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
104 lines (84 loc) · 1.93 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/robfig/cron"
"github.com/sasaxie/monitor/alerts"
"github.com/sasaxie/monitor/common/config"
"github.com/sasaxie/monitor/common/database/influxdb"
"github.com/sasaxie/monitor/datamanger"
"github.com/sasaxie/monitor/reports"
_ "github.com/sasaxie/monitor/routers"
"time"
)
func main() {
logs.Info("start monitor")
go start()
go report()
go change()
defer influxdb.Client.C.Close()
beego.Run()
}
func report() {
c := cron.New()
c.AddFunc("0 0 11 * * *", func() {
logs.Debug("report start")
r := new(reports.TotalMissed)
r.Date = time.Now().AddDate(0, 0, -1)
logs.Debug("report date", r.Date.Format("2006-01-02 15:04:05"))
r.ComputeData()
r.Save()
r.Report()
})
c.Start()
}
func change() {
c := new(alerts.ChainParameters)
c.MonitorUrl = config.MonitorConfig.Task.ProposalsMonitorUrl
logs.Info("init proposals monitor url:", c.MonitorUrl)
ticker := time.NewTicker(
time.Duration(config.MonitorConfig.Task.GetDataInterval) *
time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
c.RequestData()
c.Judge()
}
}
}
func start() {
for _, r := range datamanger.Requests {
r.Load()
}
getNowBlockAlert := new(alerts.GetNowBlockAlert)
getNowBlockAlert.Load()
listWitnessAlert := new(alerts.ListWitnessesAlert)
listWitnessAlert.Load()
ticker := time.NewTicker(
time.Duration(config.MonitorConfig.Task.GetDataInterval) *
time.Second)
defer ticker.Stop()
startAlertCount := 0
alertFinish := true
for {
select {
case <-ticker.C:
logs.Debug("start")
for _, r := range datamanger.Requests {
go r.Request()
}
time.Sleep(10 * time.Second)
startAlertCount++
if startAlertCount > 10 && alertFinish {
alertFinish = false
getNowBlockAlert.Start()
getNowBlockAlert.Alert()
listWitnessAlert.Start()
listWitnessAlert.Alert()
alertFinish = true
}
}
}
}