func (ctx *prometheusClient) Instrument(serverLabel string) func(next http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			// Begin timer
			start := time.Now()
			// Calculate request size
			reqSz := computeApproximateRequestSize(r)

			// Next request with new response writer
			sw := statusWriter{ResponseWriter: w}
			next.ServeHTTP(&sw, r)

			// Get status as string
			status := strconv.Itoa(sw.status)
			// Calculate request time
			elapsed := float64(time.Since(start)) / float64(time.Second)
			// Get response size
			resSz := float64(sw.length)

			// Manage prometheus metrics
			ctx.reqDur.WithLabelValues(serverLabel, status, r.Method, r.Host, r.URL.Path).Observe(elapsed)
			ctx.reqCnt.WithLabelValues(serverLabel, status, r.Method, r.Host, r.URL.Path).Inc()
			ctx.reqSz.WithLabelValues(serverLabel, status, r.Method, r.Host, r.URL.Path).Observe(float64(reqSz))
			ctx.resSz.WithLabelValues(serverLabel, status, r.Method, r.Host, r.URL.Path).Observe(resSz)
		})
	}
}
// Instrument will instrument gin routes.
Instrument will instrument gin routes.
// Instrument will instrument gin routes .
func (ctx *prometheusClient) Instrument(serverLabel string) func(next http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			start := time.Now()
			reqSz := computeApproximateRequestSize(r)
			sw := statusWriter{ResponseWriter: w}
			next.ServeHTTP(&sw, r)
			status := strconv.Itoa(sw.status)
			elapsed := float64(time.Since(start)) / float64(time.Second)
			resSz := float64(sw.length)
			ctx.reqDur.WithLabelValues(serverLabel, status, r.Method, r.Host, r.URL.Path).Observe(elapsed)
			ctx.reqCnt.WithLabelValues(serverLabel, status, r.Method, r.Host, r.URL.Path).Inc()
			ctx.reqSz.WithLabelValues(serverLabel, status, r.Method, r.Host, r.URL.Path).Observe(float64(reqSz))
			ctx.resSz.WithLabelValues(serverLabel, status, r.Method, r.Host, r.URL.Path).Observe(resSz)
		})
	}
}
func ( ctx * prometheusClient ) Instrument ( serverLabel string ) func ( next http . Handler ) http . Handler { return func ( next http . Handler ) http . Handler { return http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { start := time . Now ( ) reqSz := computeApproximateRequestSize ( r ) sw := statusWriter { ResponseWriter : w } next . ServeHTTP ( & sw , r ) status := strconv . Itoa ( sw . status ) elapsed := float64 ( time . Since ( start ) ) / float64 ( time . Second ) resSz := float64 ( sw . length ) ctx . reqDur . WithLabelValues ( serverLabel , status , r . Method , r . Host , r . URL . Path ) . Observe ( elapsed ) ctx . reqCnt . WithLabelValues ( serverLabel , status , r . Method , r . Host , r . URL . Path ) . Inc ( ) ctx . reqSz . WithLabelValues ( serverLabel , status , r . Method , r . Host , r . URL . Path ) . Observe ( float64 ( reqSz ) ) ctx . resSz . WithLabelValues ( serverLabel , status , r . Method , r . Host , r . URL . Path ) . Observe ( resSz ) } ) } }
Instrument will instrument gin routes.
Instrument will instrument gin routes .
// Begin timer // Calculate request size // Next request with new response writer // Get status as string // Calculate request time // Get response size // Manage prometheus metrics