-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
50 lines (46 loc) · 1.06 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
package main
import (
"flag"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/logx"
"mirouterMoinitor/config"
"mirouterMoinitor/svc"
"mirouterMoinitor/utiles/alert"
"os"
"os/signal"
"syscall"
"time"
)
var configFile = flag.String("f", "etc/config.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
// 允许配置文件调用环境变量
conf.MustLoad(*configFile, &c, conf.UseEnv())
ctx := svc.NewServiceContext(c)
// 关闭指标日志输出
logx.DisableStat()
sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
var interval = 10 * time.Second
t := time.NewTimer(interval)
defer t.Stop()
running := true
for running {
select {
case <-sig:
running = false
logx.Info("接收到程序退出信号,程序退出")
case <-t.C:
miroutertmp := alert.NewMirouterConnect(ctx)
status, err := miroutertmp.GetStatus()
if err != nil {
logx.Error(err)
t.Reset(interval)
continue
}
miroutertmp.ComputeUploadSpeed(status)
t.Reset(interval)
}
}
}