From ce75957e592c0dcba21e3c7c952c72530fd388e9 Mon Sep 17 00:00:00 2001 From: jan Date: Tue, 11 Oct 2016 15:44:33 +0200 Subject: /health route zum anzeigen von mem usage und offene db connections diff --git a/grilist/health.go b/grilist/health.go new file mode 100644 index 0000000..15697ea --- /dev/null +++ b/grilist/health.go @@ -0,0 +1,16 @@ +package grilist + +import ( + "fmt" + "net/http" + "runtime" + + "github.com/julienschmidt/httprouter" +) + +func (g *Grilist) HealthCheck(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { + var mem runtime.MemStats + runtime.ReadMemStats(&mem) + + w.Write([]byte(fmt.Sprintf("mem in use: %d\nopen g.DB connections: %d", mem.Alloc, g.DB.Stats().OpenConnections))) +} diff --git a/main.go b/main.go index 68a9ede..9231f7c 100644 --- a/main.go +++ b/main.go @@ -68,6 +68,7 @@ func main() { } router.GET("/", index) + router.GET("/health", app.HealthCheck) router.HandlerFunc("GET", "/login", login.DisplayLogin) router.HandlerFunc("POST", "/login", login.Login) router.HandlerFunc("GET", "/settings", login.DisplayUserSettings) -- cgit v0.10.1