diff options
author | Elad <theman@elad.im> | 2018-12-05 18:20:55 +0800 |
---|---|---|
committer | Anton Evangelatov <anton.evangelatov@gmail.com> | 2018-12-05 18:20:55 +0800 |
commit | 3ac633ba8423851a85cb909a1f1f0f3c0d2c5351 (patch) | |
tree | c74130bb158e59884737af2a0e578065240f667a | |
parent | b98d2e9a1c11f797502a3afa711e470a41cbc91d (diff) | |
download | dexon-3ac633ba8423851a85cb909a1f1f0f3c0d2c5351.tar dexon-3ac633ba8423851a85cb909a1f1f0f3c0d2c5351.tar.gz dexon-3ac633ba8423851a85cb909a1f1f0f3c0d2c5351.tar.bz2 dexon-3ac633ba8423851a85cb909a1f1f0f3c0d2c5351.tar.lz dexon-3ac633ba8423851a85cb909a1f1f0f3c0d2c5351.tar.xz dexon-3ac633ba8423851a85cb909a1f1f0f3c0d2c5351.tar.zst dexon-3ac633ba8423851a85cb909a1f1f0f3c0d2c5351.zip |
swarm/api/http: add resetting timer metrics to requests (#18249)
-rw-r--r-- | swarm/api/http/middleware.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/swarm/api/http/middleware.go b/swarm/api/http/middleware.go index f5f70138b..115a00856 100644 --- a/swarm/api/http/middleware.go +++ b/swarm/api/http/middleware.go @@ -5,6 +5,7 @@ import ( "net/http" "runtime/debug" "strings" + "time" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/swarm/api" @@ -73,9 +74,13 @@ func ParseURI(h http.Handler) http.Handler { func InitLoggingResponseWriter(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + startTime := time.Now() + defer metrics.GetOrRegisterResettingTimer(fmt.Sprintf("http.request.%s.time", r.Method), nil).UpdateSince(startTime) + writer := newLoggingResponseWriter(w) h.ServeHTTP(writer, r) log.Info("request served", "ruid", GetRUID(r.Context()), "code", writer.statusCode) + metrics.GetOrRegisterResettingTimer(fmt.Sprintf("http.request.%s.%d.time", r.Method, writer.statusCode), nil).UpdateSince(startTime) }) } |