448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
# File 'lib/rbvmomi/extensions.rb', line 448
def stats
filterSpec = VIM.PropertyFilterSpec(
objectSet: [{
obj: self,
selectSet: [
VIM.TraversalSpec(
name: 'tsHosts',
type: 'ComputeResource',
path: 'host',
skip: false,
)
]
}],
propSet: [{
pathSet: %w(name overallStatus summary.hardware.cpuMhz
summary.hardware.numCpuCores summary.hardware.memorySize
summary.quickStats.overallCpuUsage
summary.quickStats.overallMemoryUsage),
type: 'HostSystem'
}]
)
result = @soap.propertyCollector.RetrieveProperties(specSet: [filterSpec])
stats = {
totalCPU: 0,
totalMem: 0,
usedCPU: 0,
usedMem: 0,
}
result.each do |x|
next if x['overallStatus'] == 'red'
stats[:totalCPU] += x['summary.hardware.cpuMhz'] * x['summary.hardware.numCpuCores']
stats[:totalMem] += x['summary.hardware.memorySize'] / (1024*1024)
stats[:usedCPU] += x['summary.quickStats.overallCpuUsage']
stats[:usedMem] += x['summary.quickStats.overallMemoryUsage']
end
stats
end
|