diff --git a/cmd/sam/monitor.go b/cmd/sam/monitor.go index 4f1fa41af..e0e382862 100644 --- a/cmd/sam/monitor.go +++ b/cmd/sam/monitor.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "expvar" "fmt" "runtime" "time" @@ -21,8 +22,11 @@ type Monitor struct { } func NewMonitor(duration int) { - var m Monitor - var rtm runtime.MemStats + var ( + m = Monitor{} + rtm runtime.MemStats + goroutines = expvar.NewInt("num_goroutine") + ) var interval = time.Duration(duration) * time.Second for { <-time.After(interval) @@ -32,6 +36,7 @@ func NewMonitor(duration int) { // Number of goroutines m.NumGoroutine = runtime.NumGoroutine() + goroutines.Set(int64(m.NumGoroutine)) // Misc memory stats m.Alloc = rtm.Alloc diff --git a/cmd/sam/routes.go b/cmd/sam/routes.go index 2258290cf..3e2d49d5f 100644 --- a/cmd/sam/routes.go +++ b/cmd/sam/routes.go @@ -26,6 +26,8 @@ func MountRoutes(r chi.Router, opts *RouteOptions, mountRoutes ...func(r chi.Rou r.Use(middleware.Logger) } + r.Mount("/debug", middleware.Profiler()) + for _, mount := range mountRoutes { mount(r) }