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.
This commit is contained in:
Matthias Radestock
2016-08-25 16:13:36 +01:00
parent e8ebb31075
commit b209d22e08

View File

@@ -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 {