From 47e83c31c6cc2b4190c68ffc7253a013906c78f5 Mon Sep 17 00:00:00 2001 From: Michael Baird Date: Thu, 1 Jun 2017 15:50:30 -0500 Subject: [PATCH] capture runtime memory metrics in StatsD --- server.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server.go b/server.go index 66034e5d6..ef2c09f76 100644 --- a/server.go +++ b/server.go @@ -460,6 +460,7 @@ func (s *Server) monitorRuntime() { return } + var m runtime.MemStats ticker := time.NewTicker(s.MetricInterval) defer ticker.Stop() @@ -481,6 +482,14 @@ func (s *Server) monitorRuntime() { // Record the number of go routines s.Holder.Stats.Gauge("goroutines", float64(runtime.NumGoroutine()), 1.0) + + // Runtime memory metrics + runtime.ReadMemStats(&m) + s.Holder.Stats.Gauge("HeapAlloc", float64(m.HeapAlloc), 1.0) + s.Holder.Stats.Gauge("HeapInuse", float64(m.HeapInuse), 1.0) + s.Holder.Stats.Gauge("StackInuse", float64(m.StackInuse), 1.0) + s.Holder.Stats.Gauge("Mallocs", float64(m.Mallocs), 1.0) + s.Holder.Stats.Gauge("Frees", float64(m.Frees), 1.0) } }