-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.go
52 lines (45 loc) · 1.41 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
package main
import (
"flag"
"github.com/AliyunContainerService/alibaba-cloud-metrics-adapter/pkg/metrics/cost"
"github.com/AliyunContainerService/alibaba-cloud-metrics-adapter/pkg/provider"
"github.com/AliyunContainerService/alibaba-cloud-metrics-adapter/pkg/provider/prometheusProvider"
"k8s.io/component-base/logs"
"k8s.io/klog/v2"
"log"
"net/http"
"os"
)
func main() {
logs.InitLogs()
defer logs.FlushLogs()
opts := prometheusProvider.NewAlibabaMetricsAdapterOptions()
prometheusProvider.GlobalConfig = opts
opts.AddFlags()
opts.Flags().AddGoFlagSet(flag.CommandLine)
if err := opts.Flags().Parse(os.Args); err != nil {
klog.Fatalf("unable to parse flags: %v", err)
}
stopCh := make(chan struct{})
defer close(stopCh)
providerManager, err := provider.NewProviderManager(opts, stopCh)
if err != nil {
log.Fatalf("Failed to init alibaba-cloud-metrics-adapter,because of %v", err)
}
// register custom metrics provider
opts.WithCustomMetrics(providerManager)
// register external metrics provider
opts.WithExternalMetrics(providerManager)
// export reload endpoint
http.HandleFunc("/reload", func(writer http.ResponseWriter, request *http.Request) {
os.Exit(0)
})
// export cost metrics api
http.HandleFunc("/cost", cost.Handler)
go func() {
http.ListenAndServe(":8080", nil)
}()
if err := opts.Run(stopCh); err != nil {
klog.Fatalf("Failed to run alibaba-cloud-metrics-adapter: %v", err)
}
}