-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
87 lines (71 loc) · 1.49 KB
/
Copy pathmain.go
File metadata and controls
87 lines (71 loc) · 1.49 KB
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
package main
import (
"flag"
log "github.com/sirupsen/logrus"
"os"
"time"
)
var (
cfg *Config
)
func init() {
cfg = &Config{}
time.Local = time.UTC
var (
logLevel string
configFile string
l log.Level
err error
)
flag.StringVar(&logLevel, "log-level", "info", "allow showing debug log")
flag.StringVar(&configFile, "config", "", "configuration file path")
flag.Parse()
if logLevel == "" && os.Getenv("LOG_LEVEL") != "" {
logLevel = os.Getenv("LOG_LEVEL")
} else {
logLevel = "info"
}
if configFile == "" {
if os.Getenv("CONFIG_PATH") != "" {
configFile = os.Getenv("CONFIG_PATH")
} else {
configFile = "./config.yaml"
}
}
l, err = log.ParseLevel(logLevel)
if err != nil {
panic(err)
}
log.SetLevel(l)
cfg.logger = log.NewEntry(log.StandardLogger())
if err = loadConfig(configFile); err != nil {
panic(err)
}
}
func main() {
go prometheusExporter(cfg.logger, cfg.ctx, cfg.statsChan)
go func() {
go func() {
for {
cfg.monitorHealth(cfg.ctx, cfg.name)
}
}()
// websocket subscription and occasional validator info refreshes
for {
e := cfg.newRpc()
if e != nil {
cfg.logger.Errorf(cfg.ChainId, e)
time.Sleep(5 * time.Second)
continue
}
e = cfg.GetValInfo(true)
if e != nil {
cfg.logger.Error("🛑", cfg.ChainId, e)
}
cfg.RunBlockQuerier()
cfg.logger.Errorf(cfg.ChainId, "🌀 tendermint client exited! Restarting monitoring")
time.Sleep(5 * time.Second)
}
}()
<-cfg.ctx.Done()
}