-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
48 lines (38 loc) · 1.07 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
package main
import (
"flag"
"log"
"net/http"
"time"
"github.com/hoenn/ynab-metrics/pkg/accounts"
"github.com/hoenn/ynab-metrics/pkg/budgets"
"github.com/hoenn/ynab-metrics/pkg/categories"
"github.com/hoenn/ynab-metrics/pkg/config"
"github.com/hoenn/ynab-metrics/pkg/ratelimit"
"github.com/hoenn/ynab-metrics/pkg/transactions"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.bmvs.io/ynab"
)
var cfgFile = flag.String("config", "config.json", "The configuration file to use for exporting")
func main() {
flag.Parse()
cfg := config.ParseConfig(*cfgFile)
if cfg.AccessToken == "" {
log.Fatal("User token is empty")
}
c := ynab.NewClient(cfg.AccessToken)
go func() {
for {
budgets := budgets.GetBudgets(c)
accounts.StartMetrics(c, budgets)
categories.StartMetrics(c, budgets)
if cfg.GetTrans {
transactions.StartMetrics(c, budgets)
}
ratelimit.StartMetrics(c)
time.Sleep(time.Duration(cfg.IntervalSeconds) * time.Second)
}
}()
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":"+cfg.Port, nil))
}