github.com/vmware/transport-go@v1.3.4/plank/pkg/middleware/prometheus_metrics.go (about) 1 // Copyright 2019-2021 VMware, Inc. 2 // SPDX-License-Identifier: BSD-2-Clause 3 4 //go:build !js && !wasm 5 // +build !js,!wasm 6 7 package middleware 8 9 import ( 10 "github.com/gorilla/mux" 11 "github.com/vmware/transport-go/plank/pkg/metrics" 12 "net/http" 13 "strings" 14 ) 15 16 func SamplePrometheusMetricsMiddleware() mux.MiddlewareFunc { 17 return func(handler http.Handler) http.Handler { 18 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 19 split := strings.Split(r.URL.Path, "/") 20 metrics.PageViewCounter.WithLabelValues(split[1], r.URL.Path).Inc() 21 handler.ServeHTTP(w, r) 22 }) 23 } 24 }