summaryrefslogtreecommitdiffstats
path: root/api4/system.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-05-31 06:47:27 +0200
committerCorey Hulen <corey@hulen.com>2017-05-30 21:47:27 -0700
commitddc996f33fc39b2b8f4705d6e1232ccbad1ee4c7 (patch)
tree630c8b7b3970b2e79a5888fb9cd2c1722638cfbd /api4/system.go
parent0e4add96aebbd85d8ca7390ecc8b50ead9dbefac (diff)
downloadchat-ddc996f33fc39b2b8f4705d6e1232ccbad1ee4c7.tar.gz
chat-ddc996f33fc39b2b8f4705d6e1232ccbad1ee4c7.tar.bz2
chat-ddc996f33fc39b2b8f4705d6e1232ccbad1ee4c7.zip
[PLT-5465/APIV4] GET /system/health - Improve ping health check to have limits (#6331)
* implement PLT-5465 - Improve ping health check to have limits * update /ping and delete /health * remove permission check
Diffstat (limited to 'api4/system.go')
-rw-r--r--api4/system.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/api4/system.go b/api4/system.go
index 1f4589bf5..3a077283c 100644
--- a/api4/system.go
+++ b/api4/system.go
@@ -5,6 +5,7 @@ package api4
import (
"net/http"
+ "runtime"
"strconv"
l4g "github.com/alecthomas/log4go"
@@ -17,6 +18,7 @@ func InitSystem() {
l4g.Debug(utils.T("api.system.init.debug"))
BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET")
+
BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(getConfig)).Methods("GET")
BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(updateConfig)).Methods("PUT")
BaseRoutes.ApiRoot.Handle("/config/reload", ApiSessionRequired(configReload)).Methods("POST")
@@ -34,7 +36,19 @@ func InitSystem() {
}
func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
- ReturnStatusOK(w)
+
+ actualGoroutines := runtime.NumGoroutine()
+ if *utils.Cfg.ServiceSettings.GoroutineHealthThreshold <= 0 || actualGoroutines <= *utils.Cfg.ServiceSettings.GoroutineHealthThreshold {
+ ReturnStatusOK(w)
+ } else {
+ rdata := map[string]string{}
+ rdata["status"] = "unhealthy"
+
+ l4g.Warn(utils.T("api.system.go_routines"), actualGoroutines, *utils.Cfg.ServiceSettings.GoroutineHealthThreshold)
+
+ w.WriteHeader(http.StatusInternalServerError)
+ w.Write([]byte(model.MapToJson(rdata)))
+ }
}
func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {