示例#1
0
文件: metrics.go 项目: ycaihua/gizmo
// 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,
	}
}
示例#2
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)),
	}
}