diff options
Diffstat (limited to 'weed/server/filer_server_handlers.go')
| -rw-r--r-- | weed/server/filer_server_handlers.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/weed/server/filer_server_handlers.go b/weed/server/filer_server_handlers.go index d71b60d70..ac66514f2 100644 --- a/weed/server/filer_server_handlers.go +++ b/weed/server/filer_server_handlers.go @@ -4,6 +4,7 @@ import ( "errors" "net/http" "os" + "strconv" "strings" "sync/atomic" "time" @@ -17,7 +18,8 @@ import ( func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { start := time.Now() - + statusRecorder := stats.NewStatusResponseWriter(w) + w = statusRecorder origin := r.Header.Get("Origin") if origin != "" { if fs.option.AllowedOrigins == nil || len(fs.option.AllowedOrigins) == 0 || fs.option.AllowedOrigins[0] == "*" { @@ -53,23 +55,23 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { fileId = r.RequestURI[len("/?proxyChunkId="):] } if fileId != "" { - stats.FilerRequestCounter.WithLabelValues(stats.ChunkProxy).Inc() fs.proxyToVolumeServer(w, r, fileId) + stats.FilerHandlerCounter.WithLabelValues(stats.ChunkProxy).Inc() stats.FilerRequestHistogram.WithLabelValues(stats.ChunkProxy).Observe(time.Since(start).Seconds()) return } + defer func() { + stats.FilerRequestCounter.WithLabelValues(r.Method, strconv.Itoa(statusRecorder.Status)).Inc() + stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds()) + }() + isReadHttpCall := r.Method == "GET" || r.Method == "HEAD" if !fs.maybeCheckJwtAuthorization(r, !isReadHttpCall) { writeJsonError(w, r, http.StatusUnauthorized, errors.New("wrong jwt")) return } - stats.FilerRequestCounter.WithLabelValues(r.Method).Inc() - defer func() { - stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds()) - }() - w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION) switch r.Method { @@ -115,6 +117,8 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) { start := time.Now() + statusRecorder := stats.NewStatusResponseWriter(w) + w = statusRecorder os.Stdout.WriteString("Request: " + r.Method + " " + r.URL.String() + "\n") @@ -140,8 +144,8 @@ func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Reque w.Header().Set("Access-Control-Allow-Credentials", "true") } - stats.FilerRequestCounter.WithLabelValues(r.Method).Inc() defer func() { + stats.FilerRequestCounter.WithLabelValues(r.Method, strconv.Itoa(statusRecorder.Status)).Inc() stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds()) }() // We handle OPTIONS first because it never should be authenticated |
