VMware Cloud Community
AlbertWT
Virtuoso
Virtuoso
Jump to solution

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

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.
/* Please feel free to provide any comments or input you may have. */
1 Solution

Accepted Solutions
Grzesiekk
Expert
Expert
Jump to solution

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
Grzesiekk
Expert
Expert
Jump to solution

Hi there,

get-vmhost | Select name,NumCpu

Greg

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

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.

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

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
AlbertWT
Virtuoso
Virtuoso
Jump to solution

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

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

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
Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

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
AlbertWT
Virtuoso
Virtuoso
Jump to solution

many thanks man !

this is just what I need.

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
0v3rc10ck3d
Enthusiast
Enthusiast
Jump to solution

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!
Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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
Reply
0 Kudos
0v3rc10ck3d
Enthusiast
Enthusiast
Jump to solution

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!
Reply
0 Kudos
khanabdul01
Contributor
Contributor
Jump to solution

Hi Albert,

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

Thanks...

Abdul

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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
Reply
0 Kudos
khanabdul01
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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
Reply
0 Kudos
khanabdul01
Contributor
Contributor
Jump to solution

Thank you so much...

Reply
0 Kudos
SK90
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
abdulbaseer76
Contributor
Contributor
Jump to solution

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

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

Reply
0 Kudos