diff options
author | Corey Hulen <corey@hulen.com> | 2016-11-22 11:05:54 -0800 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2016-11-22 14:05:54 -0500 |
commit | 7961599b2e41c71720a42b3bfde641f7529f05fe (patch) | |
tree | 3c039e1d3790a954ba65fe551c7b348331bce994 /api/context.go | |
parent | e033dcce8e57ed6b6684227adf9b29347e4718b3 (diff) | |
download | chat-7961599b2e41c71720a42b3bfde641f7529f05fe.tar.gz chat-7961599b2e41c71720a42b3bfde641f7529f05fe.tar.bz2 chat-7961599b2e41c71720a42b3bfde641f7529f05fe.zip |
PLT-4357 adding performance monitoring (#4622)
* WIP
* WIP
* Adding metrics collection
* updating vendor packages
* Adding metrics to config
* Adding admin console page for perf monitoring
* Updating glide
* switching to tylerb/graceful
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) + } } } |