INNER CODE UNIT · Go
init
kubernetes-up-and-running/kuard · pkg/app/app.go:44
func init() {
prometheus.MustRegister(requestDuration)
}
var requestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "request_duration_seconds",
Help: "Time serving HTTP request",
Buckets: prometheus.DefBuckets,
}, []string{"method", "route", "status_code"})
func promMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
m := httpsnoop.CaptureMetrics(h, w, r)
requestDuration.WithLabelValues(r.Method, r.URL.Path, strconv.Itoa(m.Code)).Observe(m.Duration.Seconds())
})
}
func loggingMiddleware(handler http.Handler) http.Handler {