Merge pull request #1246 from hashicorp/fix-node-cpu-usage

Changed the logic of calculation of node cpu usage
This commit is contained in:
Diptanu Choudhury 2016-06-09 19:29:12 -07:00 committed by GitHub
commit 872957e015

View file

@ -406,11 +406,16 @@ func getActualResources(hostStats *api.HostStats, node *api.Node) ([]string, err
var resources []string
// Calculate cpu usage
usedCPUPercent := 0.0
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)
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"]