From b209d22e089be9524447dea66df9934291307f03 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 25 Aug 2016 16:13:36 +0100 Subject: [PATCH 1/2] normalise container CPU metrics to 100% The container CPU metric was reported in units of 100% = 1 CPU. So the the ratio was correct, but since we don't show limits in most places it is hard to interpret that figure. It also makes sorting by CPU usage highly misleading. So now we normalise everything to 100%. That too can be misleading, depending on what you are looking for, but it's generally less surprising. --- probe/docker/container.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/probe/docker/container.go b/probe/docker/container.go index c6ed85391..5f020e1d6 100644 --- a/probe/docker/container.go +++ b/probe/docker/container.go @@ -378,7 +378,6 @@ func (c *container) cpuPercentMetric(stats []docker.Stats) report.Metric { } samples := make([]report.Sample, len(stats)-1) - var max float64 previous := stats[0] for i, s := range stats[1:] { // Copies from docker/api/client/stats.go#L205 @@ -386,17 +385,13 @@ func (c *container) cpuPercentMetric(stats []docker.Stats) report.Metric { systemDelta := float64(s.CPUStats.SystemCPUUsage - previous.CPUStats.SystemCPUUsage) cpuPercent := 0.0 if systemDelta > 0.0 && cpuDelta > 0.0 { - cpuPercent = (cpuDelta / systemDelta) * float64(len(s.CPUStats.CPUUsage.PercpuUsage)) * 100.0 + cpuPercent = (cpuDelta / systemDelta) * 100.0 } samples[i].Timestamp = s.Read samples[i].Value = cpuPercent - available := float64(len(s.CPUStats.CPUUsage.PercpuUsage)) * 100.0 - if available >= max { - max = available - } previous = s } - return report.MakeMetric(samples).WithMax(max) + return report.MakeMetric(samples).WithMax(100.0) } func (c *container) metrics() report.Metrics { From e2a80cfa1487611450105c6b2fa46fae85475cb9 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 25 Aug 2016 16:14:42 +0100 Subject: [PATCH 2/2] correct host cpu metric The host CPU metric was reported as a percentage of all available CPUs, but the limit was set to n_cpus * 100%. So on a 4-core machine the graphs and metrics-on-canvas would never show more than 1/4th usage. Now the limit is set to 100%. Fixes #1664. --- probe/host/system_darwin.go | 2 +- probe/host/system_linux.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/probe/host/system_darwin.go b/probe/host/system_darwin.go index 33b3db5b6..b31955919 100644 --- a/probe/host/system_darwin.go +++ b/probe/host/system_darwin.go @@ -74,7 +74,7 @@ var GetUptime = func() (time.Duration, error) { return (time.Duration(d) * 24 * time.Hour) + (time.Duration(h) * time.Hour) + (time.Duration(m) * time.Minute), nil } -// GetCPUUsagePercent returns the percent cpu usage and max (ie #cpus * 100) +// GetCPUUsagePercent returns the percent cpu usage and max (i.e. 100% or 0 if unavailable) var GetCPUUsagePercent = func() (float64, float64) { return 0.0, 0.0 } diff --git a/probe/host/system_linux.go b/probe/host/system_linux.go index cde84a3f2..dbc860a0f 100644 --- a/probe/host/system_linux.go +++ b/probe/host/system_linux.go @@ -71,7 +71,7 @@ var GetUptime = func() (time.Duration, error) { var previousStat = linuxproc.CPUStat{} -// GetCPUUsagePercent returns the percent cpu usage and max (ie #cpus * 100) +// GetCPUUsagePercent returns the percent cpu usage and max (i.e. 100% or 0 if unavailable) var GetCPUUsagePercent = func() (float64, float64) { stat, err := linuxproc.ReadStat(ProcStat) if err != nil { @@ -94,7 +94,7 @@ var GetCPUUsagePercent = func() (float64, float64) { idled = idle - prevIdle ) previousStat = currentStat - return float64(totald-idled) * 100. / float64(totald), float64(len(stat.CPUStats)) * 100. + return float64(totald-idled) * 100. / float64(totald), 100. } // GetMemoryUsageBytes returns the bytes memory usage and max