-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.go
48 lines (42 loc) · 929 Bytes
/
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
package main
import (
"cosmos-validator-mission-control/config"
"cosmos-validator-mission-control/targets"
"fmt"
"log"
"sync"
"time"
client "github.com/influxdata/influxdb1-client/v2"
)
func main() {
cfg, err := config.ReadFromFile()
if err != nil {
log.Fatal(err)
}
m := targets.InitTargets(cfg)
runner := targets.NewRunner()
c, err := client.NewHTTPClient(client.HTTPConfig{
Addr: fmt.Sprintf("http://%s:%s", cfg.InfluxDB.Host, cfg.InfluxDB.Port),
Username: cfg.InfluxDB.Username,
Password: cfg.InfluxDB.Password,
})
if err != nil {
log.Fatal(err)
}
defer c.Close()
var wg sync.WaitGroup
for _, tg := range m.List {
wg.Add(1)
go func(target targets.Target) {
scrapeRate, err := time.ParseDuration(target.ScraperRate)
if err != nil {
log.Fatal(err)
}
for {
runner.Run(target.Func, target.HTTPOptions, cfg, c)
time.Sleep(scrapeRate)
}
}(tg)
}
wg.Wait()
}