From 4d3316db0ea4066aca866b40372556cbc31c1cfe Mon Sep 17 00:00:00 2001 From: "Ivan Valdes (@ivanvc)" Date: Thu, 24 Oct 2019 11:44:24 -0700 Subject: [PATCH] Fix compile error As stated in statsd/system#14, MemInfo changed from a map to a struct, breaking the compilation of the project. Trying to make this commit to master so it's not published as a patch and formalizes the fix. --- pkg/memory/memory.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/memory/memory.go b/pkg/memory/memory.go index 6f80b15..9d50d24 100644 --- a/pkg/memory/memory.go +++ b/pkg/memory/memory.go @@ -67,12 +67,12 @@ func (m *Memory) Report() { m.client.Gauge("swap.percent", swapPercent(stat)) if m.Extended { - m.client.Gauge("total", bytes(stat["MemTotal"])) + m.client.Gauge("total", bytes(stat.MemTotal)) m.client.Gauge("used", bytes(used(stat))) - m.client.Gauge("free", bytes(stat["MemFree"])) - m.client.Gauge("active", bytes(stat["Active"])) - m.client.Gauge("swap.total", bytes(stat["SwapTotal"])) - m.client.Gauge("swap.free", bytes(stat["SwapFree"])) + m.client.Gauge("free", bytes(stat.MemFree)) + m.client.Gauge("active", bytes(stat.Active)) + m.client.Gauge("swap.total", bytes(stat.SwapTotal)) + m.client.Gauge("swap.free", bytes(stat.SwapFree)) } case <-m.exit: @@ -89,9 +89,9 @@ func (m *Memory) Stop() error { } // calculate swap percentage. -func swapPercent(s linux.MemInfo) int { - total := s["SwapTotal"] - used := total - s["SwapFree"] +func swapPercent(s *linux.MemInfo) int { + total := s.SwapTotal + used := total - s.SwapFree p := float64(used) / float64(total) * 100 if math.IsNaN(p) { @@ -102,8 +102,8 @@ func swapPercent(s linux.MemInfo) int { } // calculate percentage. -func percent(s linux.MemInfo) int { - total := s["MemTotal"] +func percent(s *linux.MemInfo) int { + total := s.MemTotal p := float64(used(s)) / float64(total) * 100 if math.IsNaN(p) { @@ -114,8 +114,8 @@ func percent(s linux.MemInfo) int { } // used memory. -func used(s linux.MemInfo) uint64 { - return s["MemTotal"] - s["MemFree"] - s["Buffers"] - s["Cached"] +func used(s *linux.MemInfo) uint64 { + return s.MemTotal - s.MemFree - s.Buffers - s.Cached } // convert to bytes.