-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (45 loc) · 1020 Bytes
/
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 (
"net/http"
"pema/pkg/types"
"time"
"log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
const interval = 10
var err error
e := types.Exporter{}
_, err = e.ReadSettings()
if err != nil {
panic(err)
}
a := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "pema",
Subsystem: "mongodb_atlas",
Name: "active_clusters",
Help: "Number of clusters active with similar name/label",
},
e.Settings.GetTagNames(),
)
e.Metrics = append(e.Metrics, a)
prometheus.MustRegister(a)
http.Handle("/metrics", promhttp.Handler())
go func() {
ticker := time.NewTicker(interval * time.Second)
// register metrics in the background
for range ticker.C {
c, err := e.GetClusters()
if err != nil {
log.Fatal(err)
}
err = e.SetMetrics(c)
if err != nil {
log.Fatal(err)
}
}
}()
log.Println("serving at 5000")
log.Fatal(http.ListenAndServe(":5000", nil))
}