-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (44 loc) · 1.41 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
package main
import (
"log"
"net/http"
"time"
"github.com/NeoHuang/corona-weg/api"
"github.com/NeoHuang/corona-weg/server"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
const (
metricsSuffix = "/metrics"
listenAddress = ":8404"
)
func main() {
infectionsGauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "conrona_weg",
Subsystem: "deutschland",
Name: "status_total",
Help: "total number of infections/death",
}, []string{"bundesland", "type"})
prometheus.MustRegister(infectionsGauge)
api := api.NewMultiApi(5 * time.Minute)
go func() {
for {
epidemicMap, err := api.GetCurrent()
if err != nil {
log.Printf("Failed to get ticker from huobi %s", err)
} else {
for bundesland, epidemic := range epidemicMap {
infectionsGauge.With(prometheus.Labels{"bundesland": bundesland, "type": "infections"}).Set(float64(epidemic.Infections))
infectionsGauge.With(prometheus.Labels{"bundesland": bundesland, "type": "deaths"}).Set(float64(epidemic.Deaths))
}
}
time.Sleep(9 * time.Minute)
}
}()
// Handle Metrics endpoint
http.Handle(metricsSuffix, promhttp.Handler())
http.Handle("/api/epidemic", server.NewEpidemicHandler(api))
log.Printf("Metrics exported at http://%s%s", listenAddress, metricsSuffix)
log.Fatal(http.ListenAndServe(listenAddress, nil))
log.Printf("Shutting down......")
}