Helpful script of the day: HA calculations

I’m seeing a lot of posts on different forums about VMware HA.

Some people, including myself, have been receiving error messages when trying to power on a vm in a HA cluster like this one:

“Insufficient resources to satisfy HA failover level on cluster x in y”

Some fellow bloggers have preceeded me in providing clear explanations on how HA actually calculates this sort of thing. For instance:

 http://virtualgeek.typepad.com/virtual_geek/2008/06/so-how-exactly.html

Now, I still see a lot of replies from people that are having difficulties calculating exactly what happens in their situation. For those people, I have created a Powershell / VI Toolkit (beta) script that does the math and shows you exactly what is going on in your cluster.

So, download it, try it, and please send me some feedback if you have questions, remarks or problems.

Get-HAClusterSize

Hope this helps.

»crosslinked«

15 thoughts on “Helpful script of the day: HA calculations”

  1. I get errors running this script – am I doing something wrong… I am saving file as .ps1 then calling it from Powershell but I get the following:

    The term ‘Get-VIServer’ is not recognized as a cmdlet, function, operable program, or script file. Verify the term and
    try again.
    At C:\ha.ps1:29 char:19
    + $VC = Get-VIServer <<<< $VCServerName -ErrorAction Stop
    Get-Cluster : 02/09/2008 5:05:19 p.m. Get-Cluster You are not currently connected to any servers. Please conn
    ect first using Connect-VIServer or one of its aliases.
    At C:\ha.ps1:31 char:23
    + $Cluster = Get-Cluster <<<< $ClusterName
    Get-View : The argument cannot be null or empty.
    At C:\ha.ps1:32 char:23
    + $ClusterAdv = Get-View <<<< $Cluster.Id
    Get-VM : 02/09/2008 5:05:19 p.m. Get-VM You are not currently connected to any servers. Please connect first
    using Connect-VIServer or one of its aliases.
    At C:\ha.ps1:43 char:14
    + $VMs = Get-VM <<<< -Location $Cluster | Sort-Object Name
    Attempted to divide by zero.
    At C:\ha.ps1:49 char:86
    + Write-Progress -Activity “Processing VMs” -Status $VM.Name -PercentComplete (100*$i/$ <<<< j)
    Get-View : The argument cannot be null or empty.
    At C:\ha.ps1:52 char:19
    + $VMadv = Get-View <<<< $VM.Id
    Get-VMHost : 02/09/2008 5:05:19 p.m. Get-VMHost You are not currently connected to any servers. Please connec
    t first using Connect-VIServer or one of its aliases.
    At C:\ha.ps1:69 char:22
    + $VMHosts = Get-VMHost <<<< -Location $Cluster | Sort-Object Name
    Attempted to divide by zero.
    At C:\ha.ps1:75 char:94
    + Write-Progress -Activity “Processing VMHosts” -Status $VMHost.Name -PercentComplete (100*$k/$ <<<< l)
    Get-View : The argument cannot be null or empty.
    At C:\ha.ps1:78 char:23
    + $VMHostAdv = Get-View <<<< $VMHost.Id

  2. Nice script. I found an error in that was causing it not to calculate the MemSlots properly though.

    This line:
    Else {$MemRes = [math]::Round(($VMadv.resourceconfig.memoryallocation.reservation / 1MB),0)}

    Doesn’t need to be divided by 1MB as the number is already in megabytes. I changed to this:

    Else {$MemRes = [math]::Round(($VMadv.resourceconfig.memoryallocation.reservation),0)}

  3. Just ran this script Hi Hugo i am runing your script Get-HAClusterSize and am a bit confused.

    The results am getting are

    Your heaviest VM in terms of CPU usage is considered to be:
    a CPUSlot of 512 and a MemSlot of 522..but the server in question has 4GB of RAM…

    Am not sure how you are getting these figures….

  4. VMware uses a minimum amount of RAM needed for the VM to run for the calculation, which makes sense in the light of overcommitting your physical servers. In simple words, they say: If you lose your heaviest ESX server, let’s reserve at least enough space to host (total number of vm’s) times (*minimum* amount of resources your *heaviest* vm requires). Then we will probably be safe, because the rest of your vm’s is lighter. If they would use the allocated amounts of RAM, you will not be able to put as many vm’s on your cluster while satisfying a certain HA Failover Level.

  5. hi

    great script worked like a charm.. but i am having trouble understanding the results. The line at the bottom “you should have room for another -2vms while maintaining a failover of level of 1″ does this mean minus 2 or is that just the way the script displays the text.

    or does this mean that two of the VMs on the heaviest host will not boot?

    1. Hi Jason,

      That reads as minus two. Please note that the HA algorithm has been changed by VMware (I think since ESX3.5U4). It no longer multiplies by the highest number of vcpus in any of your vm’s. This makes the output of my script invalid.

      In the vSphere client, on the Summary Tab of your Cluster, click the Advanced Runtime Info link in the VMware HA section to show the HA adminssion control / failover level calculations.

      Hugo

  6. The current version of ESX on the cluster is currently 3.5.0 153875 does this mean the script is still valid? I do not have a advanced Runtime Info link in the HA Section just

    Do not Allow constraint Violations
    Configured failover 1
    Current failover Capacity 3

    Thanks for the help

  7. Hi Peter, your script is great!
    I grabbed it and modified it to stick to my needs.
    Now it runs inside vCheck v5 and give me HA Slot Size reports for ESX3.5/vCenter2.5 environments :)

    I’ll blog about it shortly…

    Cheers,
    Didier

  8. Hi, I am unable to run the script, I get the follwong message

    Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern ‘VMware.VimAutomation.Core’ were found. Check the pa
    ttern and then try the command again.
    At line:1 char:18
    + If ((Get-PSSnapin <<<< VMware.VimAutomation.Core) -eq $null)
    + CategoryInfo : InvalidArgument: (VMware.VimAutomation.Core:String) [Get-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : NoPSSnapInsFound,Microsoft.PowerShell.Commands.GetPSSnapinCommand

    Connect-VIServer : 9/16/2011 8:35:39 AM Connect-VIServer Could not resolve the requested VC server.
    At line:5 char:23
    + $VC = Connect-VIServer <<<< $VCServerName -ErrorAction Stop
    + CategoryInfo : ObjectNotFound: (:) [Connect-VIServer], ViServerConnectionException
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_NameResolutionFailure,VMware.VimAutomation.Vi
    Core.Cmdlets.Commands.ConnectVIServer

    I run the command Add-PSSnapin VMWare.VimAutomation.Core and then get the following error:

    Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern 'VMware.VimAutomation.Core' were found. Check the pa
    ttern and then try the command again.
    At line:1 char:18
    + If ((Get-PSSnapin <<<< VMware.VimAutomation.Core) -eq $null)
    + CategoryInfo : InvalidArgument: (VMware.VimAutomation.Core:String) [Get-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : NoPSSnapInsFound,Microsoft.PowerShell.Commands.GetPSSnapinCommand

    What am I missing??

  9. Wow interesting post. I’m curious to use those calculations. We had an extreme example because we were barely using 20% CPU and 30% RAM resources of our cluster but with a “Host failure cluster tolerates” set to 1 (of 5) we couldn’t power on another VM. Talk about conservative calculations! Thanks for the post!

Leave a Reply