mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Identify when ESXi host quickstats do not return
This commit updates cpu_utilization_for and memory_utilization_for to detect when quickstats are not present. Without this change a nil result is transformed to 0, which is perceived as a host that has no utilization.
This commit is contained in:
parent
6ab2e2ff8c
commit
ea9deddd2d
2 changed files with 25 additions and 2 deletions
|
|
@ -625,8 +625,11 @@ module Vmpooler
|
|||
cpu_utilization = cpu_utilization_for host
|
||||
memory_utilization = memory_utilization_for host
|
||||
|
||||
return nil if cpu_utilization == 0
|
||||
return nil if memory_utilization == 0
|
||||
return nil if cpu_utilization.nil?
|
||||
return nil if cpu_utilization == 0.0
|
||||
return nil if memory_utilization.nil?
|
||||
return nil if memory_utilization == 0.0
|
||||
|
||||
return nil if cpu_utilization > limit
|
||||
return nil if memory_utilization > limit
|
||||
|
||||
|
|
@ -646,12 +649,14 @@ module Vmpooler
|
|||
|
||||
def cpu_utilization_for(host)
|
||||
cpu_usage = host.summary.quickStats.overallCpuUsage
|
||||
return nil if cpu_usage.nil?
|
||||
cpu_size = host.summary.hardware.cpuMhz * host.summary.hardware.numCpuCores
|
||||
(cpu_usage.to_f / cpu_size.to_f) * 100
|
||||
end
|
||||
|
||||
def memory_utilization_for(host)
|
||||
memory_usage = host.summary.quickStats.overallMemoryUsage
|
||||
return nil if memory_usage.nil?
|
||||
memory_size = host.summary.hardware.memorySize / 1024 / 1024
|
||||
(memory_usage.to_f / memory_size.to_f) * 100
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue