VMware Cloud Community
esxi1979
Expert
Expert

script to find at cluster level ratio of total phy cores (of esxi servers) vs vcpu (of VMs) & same thing for total PRAM Vs total vRAM

Hi

Can anyone help me with script which can find at cluster level  ratio of total phy cores (of esxi servers) vs vcpu (of VMs) & same thing for total PRAM Vs total vRAM ? Not sure anyone already has similar script

Thanks

10 Replies
esxi1979
Expert
Expert

I found script from Lucd ...

Get-VMHost | Select Name,
 
@{N="pCores";E={$script:pCPU = $_.ExtensionData.Hardware.CpuINfo.NumCpuCores; $pCPU}},
 
@{N="vCores";E={
   
$script:vCPU = Get-VM -Location $_ | %{
     
$_.ExtensionData.Config.Hardware.NumCPU * $_.ExtensionData.Config.Hardware.NumCoresPerSocket
    }
| Measure-Object -Sum | Select -ExpandProperty Sum
   
$vCPU
  }}
,
 
@{N="Ratio vCore/pCore";E={[math]::Round(($script:vCPU/$script:pCPU),2)}}



If I need to get the info on cluster level ratio would be more helpful.


thanks

0 Kudos
LucD
Leadership
Leadership

To do this on a cluster level, change the first line to

$cluster = Get-Cluster -Name MyCluster
Get-VMHost -Location $cluster | Select Name,


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

esxi1979
Expert
Expert

Thanks

QQ, does this one take into account the power-off VMs ? I think yes it does.

How can we skip the power-off vms ?

Thanks

0 Kudos
LucD
Leadership
Leadership

No, the powered off VMs are included.

To exclude those, you can use a Where-clause on the Get-VM cmdlet.

Change this line

$script:vCPU = Get-VM -Location $_ | %{

into something like this

$script:vCPU = Get-VM -Location $_ | Where {$_.PowerState -eq PoweredOn} | %{


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

esxi1979
Expert
Expert

Cool ..Thanks

0 Kudos
esxi1979
Expert
Expert

Does anyone has similar script for the Memory ?

thanks

0 Kudos
LucD
Leadership
Leadership

What from the memory do you want to have the ratio for ?

The memory size with which the VM is configured vs the memory size of the ESXi server ?


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

0 Kudos
esxi1979
Expert
Expert

Yes, The memory size with which the VM is configured vs the memory size of the ESXi server, would be good.

Somehow we never consider the point in time  staticstics .. i mean say fine tune of the Mhz of current cpu user over the allocated vcpus.. ie the real time one... if we could add that .. say at the pick time of operation we would get  better idea. (in percentage may be for CPU.. for memory too the % would help)

SO in Use & Configured ... if we can both would be gr8

0 Kudos
esxi1979
Expert
Expert

Hi LucD..

I just did a cross check my manually adding the values of the cpu cores... i did found pcore it finds correctly. But the vcore are  its not giving consistent info .. can u Please re-check ?

i have esxi 5.5 &

PowerCLI C:\Windows\system32> $PSVersionTable.PSVersion

Major  Minor  Build  Revision

-----  -----  -----  --------

2      0      -1     -1

PowerCLI C:\Windows\system32>

0 Kudos
LucD
Leadership
Leadership

Yes, you are right.

Try this version

Get-VMHost | Select Name,
 
@{N="pCores";E={$script:pCPU = $_.ExtensionData.Hardware.CpuINfo.NumCpuCores; $pCPU}},
 
@{N="vCores";E={
   
$script:vCPU = Get-VM -Location $_ | %{
     
$_.ExtensionData.Config.Hardware.NumCPU
    }
| Measure-Object -Sum | Select -ExpandProperty Sum
   
$vCPU
  }}
,
 
@{N="Ratio vCore/pCore";E={[math]::Round(($script:vCPU/$script:pCPU),2)}}


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

0 Kudos