-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
50 lines (43 loc) · 952 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
49
50
package main
import (
"fmt"
"log"
"sync"
"time"
client "github.com/influxdata/influxdb1-client/v2"
"github.com/vitwit/matic-jagar/config"
"github.com/vitwit/matic-jagar/targets"
"github.com/vitwit/matic-jagar/types"
)
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("%s:%s", cfg.InfluxDB.IP, 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 types.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()
}