diff --git a/probe/host/reporter.go b/probe/host/reporter.go index a3d738788..238a4bb84 100644 --- a/probe/host/reporter.go +++ b/probe/host/reporter.go @@ -20,7 +20,7 @@ const ( Load5 = "load5" Load15 = "load15" CPUUsage = "cpu_usage_percent" - MemUsage = "mem_usage_percent" + MemUsage = "mem_usage_bytes" ) // Exposed for testing. @@ -76,7 +76,7 @@ func (r *Reporter) Report() (report.Report, error) { metrics := GetLoad(now) cpuUsage, max := GetCPUUsagePercent() metrics[CPUUsage] = report.MakeMetric().Add(now, cpuUsage).WithMax(max) - memUsage, max := GetMemoryUsagePercent() + memUsage, max := GetMemoryUsageBytes() metrics[MemUsage] = report.MakeMetric().Add(now, memUsage).WithMax(max) rep.Host.AddNode(report.MakeHostNodeID(r.hostID), report.MakeNodeWith(map[string]string{ diff --git a/probe/host/reporter_test.go b/probe/host/reporter_test.go index d5b83be9e..ed6ffd649 100644 --- a/probe/host/reporter_test.go +++ b/probe/host/reporter_test.go @@ -38,24 +38,24 @@ func TestReporter(t *testing.T) { defer mtime.NowReset() var ( - oldGetKernelVersion = host.GetKernelVersion - oldGetLoad = host.GetLoad - oldGetUptime = host.GetUptime - oldGetCPUUsagePercent = host.GetCPUUsagePercent - oldGetMemoryUsagePercent = host.GetMemoryUsagePercent + oldGetKernelVersion = host.GetKernelVersion + oldGetLoad = host.GetLoad + oldGetUptime = host.GetUptime + oldGetCPUUsagePercent = host.GetCPUUsagePercent + oldGetMemoryUsageBytes = host.GetMemoryUsageBytes ) defer func() { host.GetKernelVersion = oldGetKernelVersion host.GetLoad = oldGetLoad host.GetUptime = oldGetUptime host.GetCPUUsagePercent = oldGetCPUUsagePercent - host.GetMemoryUsagePercent = oldGetMemoryUsagePercent + host.GetMemoryUsageBytes = oldGetMemoryUsageBytes }() host.GetKernelVersion = func() (string, error) { return release + " " + version, nil } host.GetLoad = func(time.Time) report.Metrics { return load } host.GetUptime = func() (time.Duration, error) { return time.ParseDuration(uptime) } host.GetCPUUsagePercent = func() (float64, float64) { return 30.0, 100.0 } - host.GetMemoryUsagePercent = func() (float64, float64) { return 60.0, 100.0 } + host.GetMemoryUsageBytes = func() (float64, float64) { return 60.0, 100.0 } want := report.MakeReport() want.Host.AddNode(report.MakeHostNodeID(hostID), report.MakeNodeWith(map[string]string{ diff --git a/probe/host/system_darwin.go b/probe/host/system_darwin.go index e0a8278cb..e90528707 100644 --- a/probe/host/system_darwin.go +++ b/probe/host/system_darwin.go @@ -89,7 +89,7 @@ var GetCPUUsagePercent = func() (float64, float64) { return 0.0, 0.0 } -// GetMemoryUsagePercent returns the percent memory usage and max (ie 100) -var GetMemoryUsagePercent = func() (float64, float64) { +// GetMemoryUsageBytes returns the bytes memory usage and max +var GetMemoryUsageBytes = func() (float64, float64) { return 0.0, 0.0 } diff --git a/probe/host/system_linux.go b/probe/host/system_linux.go index 5c1a7846c..f28abb26e 100644 --- a/probe/host/system_linux.go +++ b/probe/host/system_linux.go @@ -13,6 +13,8 @@ import ( "github.com/weaveworks/scope/report" ) +const kb = 1024 + // Uname is swappable for mocking in tests. var Uname = syscall.Uname @@ -102,13 +104,13 @@ var GetCPUUsagePercent = func() (float64, float64) { return float64(totald-idled) * 100. / float64(totald), float64(len(stat.CPUStats)) * 100. } -// GetMemoryUsagePercent returns the percent memory usage and max (ie 100) -var GetMemoryUsagePercent = func() (float64, float64) { +// GetMemoryUsageBytes returns the bytes memory usage and max +var GetMemoryUsageBytes = func() (float64, float64) { meminfo, err := linuxproc.ReadMemInfo(ProcMemInfo) if err != nil { return 0.0, 0.0 } used := meminfo.MemTotal - meminfo.MemFree - meminfo.Buffers - meminfo.Cached - return float64(used) * 100. / float64(meminfo.MemTotal), 100. + return float64(used * kb), float64(meminfo.MemTotal * kb) }