MCPcopy
hub / github.com/caddyserver/caddy / instrumentHandlerCounter

Function instrumentHandlerCounter

metrics.go:53–62  ·  view source on GitHub ↗

Similar to promhttp.InstrumentHandlerCounter, but upper-cases method names instead of lower-casing them. Unlike promhttp.InstrumentHandlerCounter, this assumes a "code" and "method" label is present, and will panic otherwise.

(counter *prometheus.CounterVec, next http.Handler)

Source from the content-addressed store, hash-verified

51// Unlike promhttp.InstrumentHandlerCounter, this assumes a "code" and "method"
52// label is present, and will panic otherwise.
53func instrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler) http.HandlerFunc {
54 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
55 d := newDelegator(w)
56 next.ServeHTTP(d, r)
57 counter.With(prometheus.Labels{
58 "code": metrics.SanitizeCode(d.status),
59 "method": metrics.SanitizeMethod(r.Method),
60 }).Inc()
61 })
62}
63
64func newDelegator(w http.ResponseWriter) *delegator {
65 return &delegator{

Callers 1

newAdminHandlerMethod · 0.85

Calls 5

SanitizeCodeFunction · 0.92
SanitizeMethodFunction · 0.92
newDelegatorFunction · 0.85
ServeHTTPMethod · 0.65
WithMethod · 0.45

Tested by

no test coverage detected