-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.52 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
51
52
53
54
55
56
57
58
59
60
package main
import (
"context"
"flag"
"net/http"
"time"
// "encoding/json"
"github.com/almadigabor/maintenance-dash-go/internal/currentversions"
"github.com/almadigabor/maintenance-dash-go/internal/data"
"github.com/almadigabor/maintenance-dash-go/internal/latestversions"
"github.com/almadigabor/maintenance-dash-go/internal/metrics"
log "github.com/sirupsen/logrus"
)
var (
cluster *bool
kubeconfig *string
)
const refreshIntervalInSeconds = 10 //5 * 60
func parseFlags() {
// initialize flags
cluster = flag.Bool("in-cluster", false, "Specify if the code is running inside a cluster or from outside.")
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
flag.Parse()
}
func syncAppsVersionInfo() {
for {
ctx := context.Background()
var appsVersionInfo []*data.AppVersionInfo
appCurrentInfos := currentversions.GetCurrentVersions(ctx, *cluster, *kubeconfig)
for _, appCurrentInfo := range appCurrentInfos {
appVersionInfo := latestversions.GetForApp(*appCurrentInfo)
appsVersionInfo = append(appsVersionInfo, appVersionInfo)
}
metrics.UpdateMetrics(appsVersionInfo)
time.Sleep(time.Duration(refreshIntervalInSeconds * float64(time.Second)))
}
}
func main() {
log.SetFormatter(&log.JSONFormatter{})
parseFlags()
go syncAppsVersionInfo()
prometheusHandler := metrics.CreateMetrics()
// setup metrics endpoint and start server
http.Handle("/metrics", prometheusHandler)
port := ":2112"
log.Infof("Starting listening on %v", port)
http.ListenAndServe(port, nil)
}