Virtuoso
Virtuoso

List total number of vCPU per ESX host to avoid CPU over allocation when deploying VM

Jump to solution
Hi,
Can anyone please share your script to give a listing for all if VMHost / ESX CPU total count managed by VCenter that is available ?
this is for me to be able to determine whic VMhost I can deploy my VM into to avoid vCPU over allocation.
I understand that the best practice is maximum 4 single vCPU VM per core, so here's the example:
2 sockets x 6 core = 12 vCPU available
therefore there can be maximum of 12 x 4 = 48 vCPU total used maximum.
/* Any kind of comment or input would be greatly appreciated */
1 Solution

Accepted Solutions
Expert
Expert

Hi again Smiley Wink

IF you want to have a csv report from that use this 1 line:

$(foreach ($vmhost in get-vmhost){ $vms=$vmhost|get-vm;  $vmsVcpucount=($vms|Measure-Object -Property numcpu -Sum).sum; ""|Select @{N='Host';E={$vmhost.name}},@{N='cpu count';E={$vmhost.numcpu}},@{N='Actual vCPU allocated';E={$vmsVcpucount}},@{N='Max vCPU allocation';E={$vmhost.numcpu * 4}},@{N='Available vCPU allocation';E={($vmhost.numcpu * 4)-$vmsVcpucount}} }) |Export-Csv c:\rep123.csv

Greg

--- @blog https://grzegorzkulikowski.info

View solution in original post

19 Replies
Expert
Expert

Hi there,

get-vmhost | Select name,NumCpu

Greg

--- @blog https://grzegorzkulikowski.info
0 Kudos
Virtuoso
Virtuoso

hm... how to goet the number of total vCPU count for each of the ESX host ?

I need to know which ESX host is over allocated.

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
Expert
Expert

Hi there,

foreach ($vmhost in get-vmhost){
$vms=$vmhost|get-vm
$vmsVcpucount=($vms|Measure-Object -Property numcpu -Sum).sum
""|Select @{N='Host';E={$vmhost.name}},@{N='cpu count';E={$vmhost.numcpu}},@{N='Actual vCPU allocated';E={$vmsVcpucount}}
}

--- @blog https://grzegorzkulikowski.info
Virtuoso
Virtuoso

Yes, that does make sense,

can you modify the script to insert two more column which:

Maximum vCPU allocation: calculated based on 4x $vmhost.numcpu

Available vCPU allocation: calculated based on 4x $vmhost.numcpu - $vmsVcpucount

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
Expert
Expert

Hi there,

foreach ($vmhost in get-vmhost){
$vms=$vmhost|get-vm
  $vmsVcpucount=($vms|Measure-Object -Property numcpu -Sum).sum
""|Select @{N='Host';E={$vmhost.name}},@{N='cpu count';E={$vmhost.numcpu}},@{N='Actual vCPU allocated';E={$vmsVcpucount}},@{N='Max vCPU allocation';E={$vmhost.numcpu * 4}},@{N='Available vCPU allocation';E={($vmhost.numcpu * 4)-$vmsVcpucount}}
}

Greg

--- @blog https://grzegorzkulikowski.info
0 Kudos
Expert
Expert

Hi again Smiley Wink

IF you want to have a csv report from that use this 1 line:

$(foreach ($vmhost in get-vmhost){ $vms=$vmhost|get-vm;  $vmsVcpucount=($vms|Measure-Object -Property numcpu -Sum).sum; ""|Select @{N='Host';E={$vmhost.name}},@{N='cpu count';E={$vmhost.numcpu}},@{N='Actual vCPU allocated';E={$vmsVcpucount}},@{N='Max vCPU allocation';E={$vmhost.numcpu * 4}},@{N='Available vCPU allocation';E={($vmhost.numcpu * 4)-$vmsVcpucount}} }) |Export-Csv c:\rep123.csv

Greg

--- @blog https://grzegorzkulikowski.info

View solution in original post

Virtuoso
Virtuoso

many thanks man !

this is just what I need.

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
Enthusiast
Enthusiast

The way i do it is just run ESXTOP

If you SSH into a host, type in ESXTOP it's listed at the very top (how many active vCPU's are working)

VCIX6 - NV | VCAP5 - DCA / DCD / CID | vExpert 2014,2015,2016 | http://www.vcrumbs.com - My Virtualization Blog!
0 Kudos
Leadership
Leadership

Running esxtop on a host is not really a PowerCLI solution. Then you better use the PowerCLI Get-EsxTop cmdlet. Smiley Wink

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Enthusiast
Enthusiast

I haven't had my coffee yet Smiley Happy

VCIX6 - NV | VCAP5 - DCA / DCD / CID | vExpert 2014,2015,2016 | http://www.vcrumbs.com - My Virtualization Blog!
0 Kudos
Contributor
Contributor

Hi Albert,

Is ther any way to get cluster vcpu count...

Thanks...

Abdul

0 Kudos
Leadership
Leadership

Hi Abdul,

the next PowerCLI script will give you a list of all of your cluster names and the total number of vCPU's in each cluster:

Get-Cluster |

Select-Object -Property Name,

@{Name="NumCpu"

  Expression={

    $_ | Get-VM |

    Measure-Object -Property NumCpu -Sum |

    Select-Object -ExpandProperty Sum

  }

}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Contributor
Contributor

Thanks you so Much,,,

I have a specific request to get Total no of vCPUand Allocated , Free vCPUs) on the cluster. PLease give me some inputs.

Thanks
Abdul

0 Kudos
Leadership
Leadership

In your first question were you looking for the total number of cores in your hosts in a cluster or the total number of vCPU's assigned to the VM's in the cluster? Because the second option is what my script will give you. If you replace Get-VM by Get-VMHost you will get the total number of cores the hosts in a cluster have. I assume that you want to compare the number of cores the hosts have, with the number of vCPU's assigned to the VM's. Because you can assign more vCPU's to the VM's than the total number of cores in your cluster I think it is not correct to talk about allocated and free.

The next script wil give you the number of cores of all of the hosts in the cluster in the NumCpu property and the number of vCPU's of all of the VM's in the cluster in the NumCpuAllocated property:

Get-Cluster |

Select-Object -Property Name,

@{Name="NumCpu"

  Expression={

    $_ | Get-VMHost |

    Measure-Object -Property NumCpu -Sum |

    Select-Object -ExpandProperty Sum

  }

},

@{Name="NumCpuAllocated";

  Expression={

    $_ | Get-VM |

    Measure-Object -Property NumCpu -Sum |

    Select-Object -ExpandProperty Sum

  }

}


Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Contributor
Contributor

Thank you so much...

0 Kudos
Enthusiast
Enthusiast

Hi,

Can anyone help me to know how many vCPU can be in an ESXi box. configuration below.

Sockets - 4

Cores per Socket - 4

logical processor - 16

No hyperthreading

0 Kudos
Leadership
Leadership

That is hard to tell without knowing your typical workload.

You might map 1vCPU to 1pCPU, meaning no over-provisioning, which is normally underutilizing your CPU resources.


When you go for over-provisioning, you will find as many guidelines as there are design experts :smileygrin:

And truth be told, none of them knows the correct answer, since it would require monitoring your workload for a sufficiently long time.


There are some that advise to go for a 25:1 ratio, and others, the more prudent ones, that advise to go for 2:1 or 4:1.
But again, this really depends on the workload.


I personally would go for over-provisioning, and start with a prudent 4:1 ratio for example.
BUT measure the behavior of the system. Look at CPU utilisation, but also at CPU Ready, latency.... and correct if necessary-.

In short, start with moderate over-provisioning, but monitor the performance permanently, and correct the ratio if needed.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Contributor
Contributor
Thanks, dear, your efforts done in 2012 is still helping guys like me, thank god bless.
0 Kudos
Contributor
Contributor

Wow... Nice Script.

Could you please help me with same format for Memory as well.

how much actual Memory on one host, Max allocation and available allocation

0 Kudos