[PowerCLI] Report ESX vCPU vs pCPU & Memory ratio

Here is a script that will show you 3 things per host:
1. vCPU:pCPU ratio,
2. Host Memory Granted,
3. Host Memory Used.

It will count all the vCPUs on a host and the (physical) pCPUs, the vCPU differed by pCPU is the ratio. The vCPU:pCPU should in my opinion be:
High CPU load environment <4:1 Medium CPU load environment ~4:1 Low CPU load environment >4:1

The “Host Memory Granted” percentage value is the sum of all VM granted memory compared to the total host memory, you can also call this Worst-Case usage. The “Host Memory Used” percentage is the real value of the host used memory.
“Host Memory Granted” should be <90% unless you know what you are doing. "Host Memory Used" should be <80% depending on the cluster size (see Duncan’s HA Deep Dive).

$TotalNumvCPUs = 0
Foreach ($Cluster in (Get-Cluster |Sort Name)){
  $HostNumvCPUs = 0
  $HostNumvMem  = 0
  $array = @();
  Foreach ($ESXHost in ($Cluster |Get-VMHost |Sort Name)){
    Foreach ($VM in ($ESXHost |Get-VM)){ # or only powered on, Foreach ($VM in ($ESXHost |Get-VM| Where-Object {$_.PowerState -eq "PoweredOn"})){
	  $HostNumvCPUs += ($VM).NumCpu
	  $HostNumvMem  += "{0:N0}" -f ($VM).MemoryGB
    }
	$HostCPUratio   = "{0:N0}" -f ($HostNumvCPUs / ($ESXHost).NumCpu)
	$HostMemUsable  = "{0:N0}" -f (($ESXHost | Get-View).Hardware.MemorySize/1GB)
	$HostGrantedMem = "{0:N0}" -f ($HostNumvMem/$HostMemUsable*100)
	$HostUSageMem   = "{0:N0}" -f (($ESXHost).MemoryUsageGB/$HostMemUsable*100)
	
	$HostVar = @{cluster=$($Cluster.name); host=$($ESXHost.name); HostCPURatio=$HostCPUratio + ":1"; HostMemGranted=$HostGrantedMem + "%"; HostMemUsed=$HostUSageMem + "%"} 
	$Newobject = New-Object PSObject -Property $HostVar
	$array += $Newobject
        $TotalNumvCPUs += $HostNumvCPUs
	$TotalNumvMem  += $HostNumvMem
        $HostNumvCPUs = 0
	$HostNumvMem  = 0
  }
  $array | Select-Object cluster,host,HostCPURatio,HostMemGranted,HostMemUSed | Format-Table -AutoSize
  $TotalNumvCPUs = 0
  $TotalNumvMem  = 0
}

Output:
CheckResources

Leave a Reply

Your email address will not be published. Required fields are marked *