-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
36 lines (32 loc) · 898 Bytes
/
metrics.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
package main
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"net/http"
)
var (
resolveMissingTotal = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "image_missing",
Help: "Image missing in registry",
},
[]string{"image"},
)
)
func healthcheckHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprintf(w, "OK")
if err != nil {
log.Errorf("error responding to request %v", err)
}
}
func startMetricsServer(port int) error {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
mux.HandleFunc("/health", healthcheckHandler)
log.Printf("Starting metrics server on port %d", port)
return http.ListenAndServe(fmt.Sprintf(":%d", port), mux)
}