-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
55 lines (46 loc) · 1.51 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
package main
import (
"net/http"
"os"
"github.com/kenfdev/remo-exporter/config"
"github.com/kenfdev/remo-exporter/exporter"
authHttp "github.com/kenfdev/remo-exporter/http"
"github.com/kenfdev/remo-exporter/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
log.Info("Starting Nature Remo Exporter")
r := config.NewFileReader()
c, err := config.NewConfig(r)
if err != nil {
log.Errorf("Failed to create config: %v", err)
os.Exit(1)
}
authClient := authHttp.NewAuthHttpClient(c.OAuthToken)
rc, err := exporter.NewRemoClient(c, authClient)
if err != nil {
log.Errorf("Failed to create remo client: %v", err)
os.Exit(1)
}
e, err := exporter.NewExporter(c, rc)
if err != nil {
log.Errorf("Failed to create exporter: %v", err)
os.Exit(1)
}
prometheus.MustRegister(e)
http.Handle(c.MetricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Nature Remo Exporter</title></head>
<body>
<h1>Nature Remo Prometheus Metrics Exporter</h1>
<p>For more information, visit <a href=https://github.com/kenfdev/remo-exporter>GitHub</a></p>
<p><a href='` + c.MetricsPath + `'>Metrics</a></p>
</body>
</html>
`))
})
log.Infof("Listening on :%s", c.ListenPort)
log.Fatal(http.ListenAndServe(":"+c.ListenPort, nil))
}