Example #1
0
// Timed returns an http.Handler that starts a timer, passes requests to an
// underlying http.Handler, stops the timer, and updates the timer via
// go-kit/kit/metrics.
func Timed(handler http.Handler, name string, p provider.Provider) *Timer {
	hist, err := p.NewHistogram(name,
		fmt.Sprintf("tracking request duration for %q", name),
		0, 1500000, 4, // 0-15 minute time range, 4 sigfigs
		50, 75, 90, 95, 99) // quantiles
	if err != nil {
		panic("invalid histogram settings")
	}

	return &Timer{
		TimeHistogram: metrics.NewTimeHistogram(time.Millisecond, hist),
		handler:       handler,
	}
}
Example #2
0
// CountedByStatusXX returns an http.Handler that passes requests to an
// underlying http.Handler and then counts the response by the first digit of
// its HTTP status code via go-kit/kit/metrics.
func CountedByStatusXX(handler http.Handler, name string, p provider.Provider) *CounterByStatusXX {
	return &CounterByStatusXX{
		counter1xx: p.NewCounter(fmt.Sprintf("%s-1xx", name),
			fmt.Sprintf("counting responses to %q with a status code of 1XX", name)),
		counter2xx: p.NewCounter(fmt.Sprintf("%s-2xx", name),
			fmt.Sprintf("counting responses to %q with a status code of 2XX", name)),
		counter3xx: p.NewCounter(fmt.Sprintf("%s-3xx", name),
			fmt.Sprintf("counting responses to %q with a status code of 3XX", name)),
		counter4xx: p.NewCounter(fmt.Sprintf("%s-4xx", name),
			fmt.Sprintf("counting responses to %q with a status code of 4XX", name)),
		counter5xx: p.NewCounter(fmt.Sprintf("%s-5xx", name),
			fmt.Sprintf("counting responses to %q with a status code of 5XX", name)),
		handler: handler,
	}
}
Example #3
0
func registerRPCMetrics(name string, mets provider.Provider) {
	name = "rpc." + name
	hist, err := mets.NewHistogram(name+".DURATION",
		fmt.Sprintf("tracking request duration for %q", name),
		0, 1500000, 4, // 0-15min time range
		50, 75, 90, 95, 99)
	if err != nil {
		panic(fmt.Sprint("invalid histogram settings: ", err))
	}
	rpcEndpointMetrics[name] = &rpcMetrics{
		Timer: metrics.NewTimeHistogram(time.Millisecond, hist),
		SuccessCounter: mets.NewCounter(name+".SUCCESS",
			fmt.Sprintf("counting successful repsonses for %s", name)),
		ErrorCounter: mets.NewCounter(name+".ERROR",
			fmt.Sprintf("counting error responses for %s", name)),
		PanicCounter: mets.NewCounter(name+".PANIC",
			fmt.Sprintf("counting paniced responses for %s", name)),
	}
}