This post is more than 5 years old
22 Posts
0
135714
April 10th, 2012 17:00
Powered off VM stats
I am trying to create a dashboard that will show all the VMs in a datacenter with # cpu, memory size, and storage size. I can get that info for VMs that are powered on: virtualMachine.get("cpus/cores/latest/average")
but for powered-off VMs, that will return n/a
What should I do?


DELL-Thomas B
171 Posts
1
April 11th, 2012 03:00
The only way to get those is if the VM is powered on. What you can get is the total allocated storage, regardless of powerstate based on the VMDK file layouts. To do this, you need to sum up all of the disks (if the VM has any) and then divide to get you the units you want. This little code snippit I use in a lot of places for the exact reason.
I use vm as a variable in a function that used the type VMWVirtualMachine or you can run this in script editor from a VMWVirtualMachine and pass something like vm = scope based on a VM you selected
//begin code
result = 0
// Disk Calculation
list = vm.get("vmdkFileLayouts")
if(list.size() == 0)
{
totalDisk = 0
}
else
{
disk = list.diskSize.sum()
removeDisk = list[0].diskSize
totalDisk = disk / 1024 / 1024 / 1024 // Convert to GB
}
// Add data to result
result = totalDisk
return result
changf03
22 Posts
0
April 10th, 2012 17:00
I was able to get the cpu and memory data using the commands:
vm.cpus.cores.latest.average
vm.memory.allocated.latest.average
but when I try any of the these commands:
vm.host.storage.spaceUsed.latest.average
vm.host.storage.spaceUsed.current.average
vm.host.storage.spaceUsed.period.max
nothing is returned. How can I get the size of the VM even if it is turned off?
changf03
22 Posts
0
April 12th, 2012 17:00
Thanks Thomas, it worked like a charm