From 23eb6e5292bc5602eac761120f98a75a27f8b3ae Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Wed, 13 Apr 2022 12:51:23 +0200 Subject: [PATCH] Cleaning up debug toolings --- pkg/api/server/handlers.go | 4 +-- pkg/monitor/monitor.go | 54 ++++++++++++-------------------------- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/pkg/api/server/handlers.go b/pkg/api/server/handlers.go index 6cf82f359..2bb94d369 100644 --- a/pkg/api/server/handlers.go +++ b/pkg/api/server/handlers.go @@ -183,8 +183,8 @@ func mountDebugHandler(r chi.Router, log *zap.Logger) { log.Debug("route debugger enabled: /__routes") r.Get("/__routes", debugRoutes(r)) - log.Debug("profiler enabled: /__profiler") - r.Mount("/__profiler", middleware.Profiler()) + log.Debug("profiler enabled: /debug/pprof") + r.Mount("/debug", middleware.Profiler()) log.Debug("eventbus handlers debug enabled: /__eventbus") r.Get("/__eventbus", debugEventbus()) diff --git a/pkg/monitor/monitor.go b/pkg/monitor/monitor.go index 87f21eb2f..c39160622 100644 --- a/pkg/monitor/monitor.go +++ b/pkg/monitor/monitor.go @@ -2,7 +2,6 @@ package monitor import ( "context" - "expvar" "runtime" "time" @@ -12,16 +11,16 @@ import ( ) type Monitor struct { - Alloc, - TotalAlloc, - Sys, - Mallocs, - Frees, - LiveObjects, - PauseTotalNs uint64 - - NumGC uint32 - NumGoroutine int + //Alloc, + //TotalAlloc, + //Sys, + //Mallocs, + //Frees, + //LiveObjects, + //PauseTotalNs uint64 + // + //NumGC uint32 + //NumGoroutine int } var ( @@ -52,10 +51,7 @@ func Watcher(ctx context.Context) { func NewMonitor(ctx context.Context, interval time.Duration) { var ( - m = Monitor{} - rtm runtime.MemStats - goroutines = expvar.NewInt("num_goroutine") - ticker = time.NewTicker(interval) + ticker = time.NewTicker(interval) ) defer ticker.Stop() @@ -64,36 +60,20 @@ func NewMonitor(ctx context.Context, interval time.Duration) { select { case <-ticker.C: // Read full mem stats - runtime.ReadMemStats(&rtm) - - // Number of goroutines - m.NumGoroutine = runtime.NumGoroutine() - goroutines.Set(int64(m.NumGoroutine)) - - // Misc memory stats - m.Alloc = rtm.Alloc - m.TotalAlloc = rtm.TotalAlloc - m.Sys = rtm.Sys - m.Mallocs = rtm.Mallocs - m.Frees = rtm.Frees - - // Live objects = Mallocs - Frees - m.LiveObjects = m.Mallocs - m.Frees - - // GC Stats - m.PauseTotalNs = rtm.PauseTotalNs - m.NumGC = rtm.NumGC + m := new(runtime.MemStats) + runtime.ReadMemStats(m) log.With( - zap.Uint64("alloc", m.Alloc), + zap.Uint64("alloc", m.HeapAlloc), zap.Uint64("totalAlloc", m.TotalAlloc), zap.Uint64("sys", m.Sys), zap.Uint64("mallocs", m.Mallocs), zap.Uint64("frees", m.Frees), - zap.Uint64("liveObjects", m.LiveObjects), + + zap.Uint64("liveObjects", m.Mallocs-m.Frees), zap.Uint64("pauseTotalNs", m.PauseTotalNs), zap.Uint32("numGC", m.NumGC), - zap.Int("numGoRoutines", m.NumGoroutine), + zap.Int("numGoRoutines", runtime.NumGoroutine()), ).Info("tick") case <-ctx.Done():