added size to instrumentation

This commit is contained in:
franklin 2017-01-27 17:18:23 +01:00
parent a9c02ee989
commit 2c24d2c7a1

View File

@ -8,22 +8,32 @@ import (
)
func InstrumentService(s http.HandlerFunc) (handler http.HandlerFunc) {
counterVec := p.NewSummaryVec(p.SummaryOpts{
requestDuration := p.NewSummaryVec(p.SummaryOpts{
Namespace: "gotsrpc",
Subsystem: "service",
Name: "time_nanoseconds",
Help: "nanoseconds to unmarshal requests, execute a service function and marshal its reponses",
}, []string{"package", "service", "func", "type"})
p.MustRegister(counterVec)
requestSize := p.NewSummaryVec(p.SummaryOpts{
Namespace: "gotsrpc",
Subsystem: "service",
Name: "size_bytes",
Help: "request and response sizes in bytes",
}, []string{"package", "service", "func", "type"})
p.MustRegister(requestSize)
p.MustRegister(requestDuration)
return func(w http.ResponseWriter, r *http.Request) {
*r = *gotsrpc.RequestWithStatsContext(r)
s.ServeHTTP(w, r)
stats := gotsrpc.GetStatsForRequest(r)
if stats != nil {
counterVec.WithLabelValues(stats.Package, stats.Service, stats.Func, "unmarshalling").Observe(float64(stats.Unmarshalling))
counterVec.WithLabelValues(stats.Package, stats.Service, stats.Func, "execution").Observe(float64(stats.Execution))
counterVec.WithLabelValues(stats.Package, stats.Service, stats.Func, "marshalling").Observe(float64(stats.Marshalling))
requestSize.WithLabelValues(stats.Package, stats.Service, stats.Func, "request").Observe(float64(stats.RequestSize))
requestSize.WithLabelValues(stats.Package, stats.Service, stats.Func, "response").Observe(float64(stats.ResponseSize))
requestDuration.WithLabelValues(stats.Package, stats.Service, stats.Func, "unmarshalling").Observe(float64(stats.Unmarshalling))
requestDuration.WithLabelValues(stats.Package, stats.Service, stats.Func, "execution").Observe(float64(stats.Execution))
requestDuration.WithLabelValues(stats.Package, stats.Service, stats.Func, "marshalling").Observe(float64(stats.Marshalling))
}
}
}