-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (44 loc) · 1.12 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
package main
import (
"flag"
"log"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
type Config struct {
WebAddr string `arg:"env:WEB_ADDR"`
WebPath string `arg:"env:WEB_PATH"`
}
func main() {
var syncoveryUrl string
flag.StringVar(&syncoveryUrl, "url", "", "Syncovery instance url")
flag.Parse()
if len(syncoveryUrl) == 0 {
flag.Usage()
os.Exit(1)
}
client, err := CreateSyncoveryClient(syncoveryUrl)
if err != nil {
panic(err)
}
registry := prometheus.NewPedanticRegistry()
registry.MustRegister(NewSyncoveryCollector(client))
c := Config{
WebPath: "/metrics",
WebAddr: ":8080",
}
http.Handle(c.WebPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Syncovery Exporter</title></head>
<body>
<h1>Syncovery Exporter</h1>
<p><a href="` + c.WebPath + `">Metrics</a></p>
</body>
</html>`))
})
log.Println("Collector launched on port 8080")
log.Fatal(http.ListenAndServe(c.WebAddr, nil))
}