-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
57 lines (45 loc) · 1.39 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
package main
import (
"flag"
"fmt"
"github.com/ebauman/prometheus-rancher-exporter/collector"
"github.com/ebauman/prometheus-rancher-exporter/query/rancher"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/tools/clientcmd"
"net/http"
"os/user"
)
func main() {
// Build Rancher Client
log.Info("Building Rancher Client")
// Use this for in-cluster config
// config, err := rest.InClusterConfig()
// Use this for out of cluster config
currentUser, err := user.Current()
if err != nil {
log.Fatal(err.Error())
}
kubeconfig := flag.String("kubeconfig", fmt.Sprintf("/home/%s/.kube/config", currentUser.Username), "absolute path to the kubeconfig file")
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
log.Fatal("Unable to construct Rancher client Config")
}
client, err := dynamic.NewForConfig(config)
if err != nil {
log.Fatal("Unable to construct Rancher client")
}
RancherClient := rancher.Client{
Config: config,
Client: client,
}
//Kick off collector in background
go collector.Collect(RancherClient)
//This section will start the HTTP server and expose
//any metrics on the /metrics endpoint.
http.Handle("/metrics", promhttp.Handler())
log.Info("Beginning to serve on port :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}