-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
62 lines (41 loc) · 1.59 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
61
62
package main
import (
"net/http"
"os"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"github.com/zolamk/hasura-exporter/collector"
"github.com/zolamk/hasura-exporter/settings"
)
func main() {
logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.SetOutput(os.Stdout)
level, _ := logrus.ParseLevel(settings.LogLevel)
logrus.SetLevel(level)
registry := prometheus.NewRegistry()
errors := prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "hasura_errors_total",
Help: "the total number of errors per collector",
}, []string{"collector"})
timeout := time.Duration(10) * time.Second
registry.MustRegister(errors)
registry.MustRegister(collector.NewMetadataCollector(errors, timeout))
registry.MustRegister(collector.NewEventTriggerCollector(errors, timeout))
registry.MustRegister(collector.NewCronTriggerCollector(errors, timeout))
registry.MustRegister(collector.NewScheduledEventsCollector(errors, timeout))
registry.MustRegister(collector.NewHealthcheckCollector(errors, timeout))
http.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`<html>
<head><title>Hasura Exporter</title></head>
<body>
<h1>Hasura Exporter</h1>
<p><a href="` + settings.WebAddr + `/metrics">Metrics</a></p>
</body>
</html>`))
})
logrus.Info("started hasura exporter on ", settings.WebAddr)
logrus.WithField("msg", http.ListenAndServe(settings.WebAddr, nil)).Fatalln()
}