Merge pull request #1259 from hashicorp/fix-node-ticks

Fixed the calculation of the host node ticks
This commit is contained in:
Diptanu Choudhury 2016-06-11 16:25:34 -07:00 committed by GitHub
commit 4cdcc6d5bb

View file

@ -85,23 +85,20 @@ func (h *HostStatsCollector) Collect() (*HostStats, error) {
if cpuStats, err := cpu.Times(true); err == nil {
cs := make([]*CPUStats, len(cpuStats))
for idx, cpuStat := range cpuStats {
cs[idx] = &CPUStats{
CPU: cpuStat.CPU,
User: cpuStat.User,
System: cpuStat.System,
Idle: cpuStat.Idle,
}
percentCalculator, ok := h.statsCalculator[cpuStat.CPU]
if !ok {
percentCalculator = NewHostCpuStatsCalculator()
h.statsCalculator[cpuStat.CPU] = percentCalculator
}
idle, user, system, total := percentCalculator.Calculate(cpuStat)
cs[idx].Idle = idle
cs[idx].System = system
cs[idx].User = user
cs[idx].Total = total
ticksConsumed += (total / 100) * shelpers.TotalTicksAvailable()
cs[idx] = &CPUStats{
CPU: cpuStat.CPU,
User: user,
System: system,
Idle: idle,
Total: total,
}
ticksConsumed += (total / 100) * (shelpers.TotalTicksAvailable() / float64(len(cpuStats)))
}
hs.CPU = cs
hs.CPUTicksConsumed = ticksConsumed