diff options
Diffstat (limited to 'api/context.go')
-rw-r--r-- | api/context.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/api/context.go b/api/context.go index 7466d0b05..3a867624b 100644 --- a/api/context.go +++ b/api/context.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" "strings" + "time" l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" @@ -103,6 +104,7 @@ type handler struct { } func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + now := time.Now() l4g.Debug("%v", r.URL.Path) c := &Context{} @@ -228,6 +230,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if h.isApi { w.WriteHeader(c.Err.StatusCode) w.Write([]byte(c.Err.ToJson())) + + if einterfaces.GetMetricsInterface() != nil { + einterfaces.GetMetricsInterface().IncrementHttpError() + } } else { if c.Err.StatusCode == http.StatusUnauthorized { http.Redirect(w, r, c.GetTeamURL()+"/?redirect="+url.QueryEscape(r.URL.Path), http.StatusTemporaryRedirect) @@ -235,6 +241,16 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { RenderWebError(c.Err, w, r) } } + + } + + if h.isApi && einterfaces.GetMetricsInterface() != nil { + einterfaces.GetMetricsInterface().IncrementHttpRequest() + + if r.URL.Path != model.API_URL_SUFFIX+"/users/websocket" { + elapsed := float64(time.Since(now)) / float64(time.Second) + einterfaces.GetMetricsInterface().ObserveHttpRequestDuration(elapsed) + } } } |