From 7579567f597ce82b960c1c5d253b5d861eeb0a12 Mon Sep 17 00:00:00 2001 From: Michael Baird Date: Tue, 16 May 2017 15:28:18 -0500 Subject: [PATCH] return early when metrics are disabled --- server.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/server.go b/server.go index eae9dd4c7..2c86ad4ae 100644 --- a/server.go +++ b/server.go @@ -449,29 +449,32 @@ func checkMaxSlices(hostport string) (map[string]uint64, error) { // monitorRuntime periodically polls the Go runtime metrics. func (s *Server) monitorRuntime() { - if s.MetricInterval > 0 { - ticker := time.NewTicker(s.MetricInterval) - defer ticker.Stop() + // Disable metrics when poll interval is zero + if s.MetricInterval <= 0 { + return + } - gcn := gcnotifier.New() - defer gcn.Close() + ticker := time.NewTicker(s.MetricInterval) + defer ticker.Stop() - s.logger().Printf("runtime stats initializing (%s interval)", s.MetricInterval) + gcn := gcnotifier.New() + defer gcn.Close() - for { - // Wait for tick or a close. - select { - case <-s.closing: - return - case <-gcn.AfterGC(): - // GC just ran - s.Holder.Stats.Count("garbage_collection", 1, 1.0) - case <-ticker.C: - } + s.logger().Printf("runtime stats initializing (%s interval)", s.MetricInterval) - // Record the number of go routines - s.Holder.Stats.Gauge("goroutines", float64(runtime.NumGoroutine()), 1.0) + for { + // Wait for tick or a close. + select { + case <-s.closing: + return + case <-gcn.AfterGC(): + // GC just ran + s.Holder.Stats.Count("garbage_collection", 1, 1.0) + case <-ticker.C: } + + // Record the number of go routines + s.Holder.Stats.Gauge("goroutines", float64(runtime.NumGoroutine()), 1.0) } }