From e4bad88a87a16c7025e69fce08cd516041e8b27f Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Fri, 10 Jun 2016 03:24:42 +0100 Subject: [PATCH] Changed the logic of calculation of node cpu usage --- command/node_status.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/command/node_status.go b/command/node_status.go index ea8719d09..2595d3a7c 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -406,11 +406,16 @@ func getActualResources(hostStats *api.HostStats, node *api.Node) ([]string, err var resources []string // Calculate cpu usage - usedCPUPercent := 0.0 - for _, cpu := range hostStats.CPU { - usedCPUPercent += (cpu.User + cpu.System) + usedCPUTicks := 0.0 + if freq, ok := node.Attributes["cpu.frequency"]; ok { + + if clkSpeed, err := strconv.ParseFloat(freq, 64); err == nil { + for _, cpu := range hostStats.CPU { + usedCPUPercent := (cpu.User + cpu.System) + usedCPUTicks += (clkSpeed * usedCPUPercent / 100) + } + } } - usedCPUTicks := (usedCPUPercent / 100) * float64(node.Resources.CPU) // calculate disk usage storageDevice := node.Attributes["unique.storage.volume"]