Home > Uncategorized > ESX3.5/vCenter2.5 Slot Size Calculation For vCheck v5

ESX3.5/vCenter2.5 Slot Size Calculation For vCheck v5


I’ve been working like crazy the last four weeks on different projects. One of them was about a Powershell script that would do HA Slot Size calculation for an ESX3.5/vCenter2.5 environment.

Like a lot of vAdmins I use Alan Renouf‘s vCheck v5 to produce valuable reports but there was an issue, a big one!

vCheck does HA Slot Size calculation but for vSphere based environment only. Actually the code tests if $vSphere -eq $true before running the Cluster Slot Sizes module…

No worries I thought, let’s google for Powershell scripts that would do HA Slot Size calculation for an ESX3.5/vCenter2.5 environment.

Well there isn’t any! Almost any actually… I found out a great blog post by Hugo Peeters @ http://www.peetersonline.nl who gives out a Powershell script that does exactly what I was looking for.

The code dated from July 2008 and used VMware VI Toolkit which was still in beta at that time. I managed to integrate it into the latest vCheck v5 which became de facto THE free reporting tool for VMware virtual environments. I also modified the code to stick to my needs and requirements, and that’s pretty much all I did.

This was a great experience because I’m not a so called developer. Doing this project helped me deep dive, well at least it was deep dive for me, into Powershell, VMware PowerCLI and Alan’s great vCheck v5 script.

Let me share this piece of code with you and hope you will find it useful for your daily work as a vAdmin. Do not hesitate to post comments or eventually request new functionalities since Ive quite enjoyed express the ‘developer’ side of my personality :)

And once again this script is based on the great work of Hugo Peeters @ http://www.peetersonline.nl. Thx Hugo, you saved my day ;)

Here is a screenshot showing the output into a vCheck v5 report.

Here are some explanations on how to add this into vCheck v5. First, you need to add a couple of lines at the bottom of the section where you turn on or off certain area of a vCheck V5 report.

#HA Slot Size Info for Version 3 Environment
$HASlotSizeV3 = $true

Second, copy/paste the highlighted code below and paste it into vCheck v5 just right before the line: # Capacity Planner Info

Finally, save the script and run it as you would run any vCheck v5 script.

A final reminder: Don’t try this on a production environment (don’t even think about it) and read the disclaimer at the bottom of this blog post! I shall not be liable for any damages arising out!

# HA Slot Size Info for Version 3 Environments
if ($HASlotSizeV3) {
If ($vSphere -ne $True){
Write-CustomOut "..Checking HA Slot Size Info for a Version 3 Environment"

######################################################
# Get-HAClusterSize by Hugo Peeters available @ http://www.peetersonline.nl
# Didier Pironet - Script kidding the great work of Hugo Peeters
######################################################

###########
# Variables
###########
# General (do not modify)
$DefaultCPURes = 256
$DefaultMemoryRes = 344
$clusHACapacityInfo = @()

##################
# Script execution
##################
Foreach ($Clustername in (Get-Cluster |Sort Name)) {
$clusHACapacity = "" |Select ClusterName, "HA Slot Size", "HA Admission Control Status", "HA FailOver Level of 'x' Host(s)"

$clusHACapacity.ClusterName = ($Clustername.Name)
$clusHACapacity."HA Slot Size" = 0
$clusHACapacity."HA Admission Control Status" = "True"
$clusHACapacity."HA FailOver Level of 'x' Host(s)" = 1
$VMs = (Get-VM -Location $Clustername | Sort-Object Name)

#############
# Process VMs
#############
IF ($VMs -ne $null) {
write-host ""
write-host "---------------------------------------------------------------------------------"
write-host "clustername: " $Clustername
$Cluster = Get-Cluster $ClusterName
write-host "cluster: " $Cluster
$ClusterAdv = Get-View $Cluster.Id

$HAAdmissionControlInfo = get-cluster $ClusterName | select *
$vmCPUMinMHz = ($ClusterAdv.configuration.dasconfig.option | Where {$_.Key -eq "das.vmCpuMinMHz"}).Value
If ($vmCPUMinMHz){$MinCPUReservation = $vmCPUMinMHz}
Else {$MinCPUReservation = $DefaultCPURes}
$vmMemoryMinMB = ($ClusterAdv.configuration.dasconfig.option | Where {$_.Key -eq "vmMemoryMinMB"}).Value
If ($vmMemoryMinMB){$MinMemoryReservation = $vmMemoryMinMB}
Else {$MinMemoryReservation = $DefaultMemoryRes}

$myVMcol = @()
$i = 1
$j = $VMs.length
ForEach ($VM in $VMs)
{
$myVMobj = "" | Select-Object Name, CPUSlot, MemSlot, NumCpu
$myVMobj.Name = $VM.Name
$VMadv = Get-View $VM.Id

$VMView = $VM | Get-View
$VMInfo = {} | Select NumCPU
IF ($vm.NumCPU >=1) {$VMInfo.NumCPU = $vm.NumCPU}
else {$VMInfo.NumCPU=1}

If ($VMadv.resourceconfig.cpuallocation.reservation -eq 0){$CPURes = ($MinCPUReservation * $VMInfo.NumCPU)}
Else {$CPURes = [math]::Round((($VMadv.resourceconfig.cpuallocation.reservation/1000000) * $VMInfo.NumCPU),0)}

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

$myVMobj.CPUSlot = $CPURes
$myVMobj.MemSlot = [math]::Round((($VMadv.runtime.memoryoverhead / 1MB ) + $MemRes),0)
$myVMobj.NumCpu = $VMInfo.NumCPU

$myVMobj | Format-Table -AutoSize

$myVMcol += $myVMobj
Clear-Variable CPURes
Clear-Variable MemRes
$i++
}

IF ((($myVMcol | Sort-Object CPUSlot -Descending | Select-Object -First 1).CPUSlot) -eq 0) {$MaxCPUSlot = $DefaultCPURes}
else {$MaxCPUSlot = ($myVMcol | Sort-Object CPUSlot -Descending | Select-Object -First 1).CPUSlot}

IF ((($myVMcol | Sort-Object MemSlot -Descending | Select-Object -First 1).MemSlot) -eq 0) {$MaxMemSlot = $DefaultMemoryRes}
else {$MaxMemSlot = ($myVMcol | Sort-Object MemSlot -Descending | Select-Object -First 1).MemSlot}
}

#################
# Process VMHosts
#################
$VMHosts = Get-VMHost -Location $Cluster | Sort-Object Name
$myVMHostCol = @()
$k = 1
$l = $VMHosts.length
ForEach ($VMHost in $VMHosts)
{
$myVMHostObj = "" | Select-Object Name, CPU, CPUSlots, Memory, MemSlots
$myVMHostObj.Name = $VMHost.Name
$VMHostAdv = Get-View $VMHost.Id
$myVMHostObj.CPU = [math]::Round(($VMHostAdv.hardware.cpuinfo.numcputhreads * $VMHostAdv.hardware.cpuinfo.hz / 1000000),0)
$myVMHostObj.CPUSlots = [math]::Floor($myVMHostObj.CPU / $MaxCPUSlot)
$myVMhostObj.Memory = [math]::Round(($VMHostAdv.hardware.memorysize / 1MB),0)
$myVMHostObj.MemSlots = [math]::Floor((($myVMHostObj.Memory)-1600) / $MaxMemSlot)
$myVMHostCol += $myVMHostObj
$k++

##############
# Calculations
##############
$TotalCPUSlots = ($myVMHostCol | Sort-Object CPUSlots | Select-Object -First ($myVMHostCol.Length - $Cluster.HAFailoverLevel) | Measure-Object -Property CPUSlots -Sum).Sum
$TotalMemSlots = ($myVMHostCol | Sort-Object MemSlots | Select-Object -First ($myVMHostCol.Length - $Cluster.HAFailoverLevel) | Measure-Object -Property MemSlots -Sum).Sum
If ($TotalMemSlots -lt $TotalCPUslots){$capacity = $TotalMemSlots}
Else {$capacity = $TotalCPUslots}
$available = ($capacity - $VMs.Length)
}

########
# Output
########
write-host ""
Write-Host "------------------------------------"
Write-Host "Your heaviest VM in terms of CPU usage is: "
$myVMcol | Sort-Object CPUSlot, MemSlot -Descending | Select-Object -First 1 | Format-Table -AutoSize
Write-Host "Your heaviest VM in terms of MEM usage is: "
$myVMcol | Sort-Object MemSlot -Descending | Select-Object -First 1 | Format-Table -AutoSize
write-host ""
Write-Host "------------------------------------"
Write-Host "Your cluster has the following VMHosts:"
$myVMHostCol | Format-Table -AutoSize
Write-Host "If you should lose your heaviest VMHost, you would have left:"
Write-Host " Total Number of CPU slots: $TotalCPUSlots"
Write-Host " Total Number of MEM slots: $TotalMemSlots"
write-host ""
Write-Host "------------------------------------"
$MostRestrictiveValue = [math]::Min($TotalCPUSlots,$TotalMemSlots)
Write-Host "vCenter2.5 uses the most restrictive value from above to set the HA Slot Size, that is: $MostRestrictiveValue"
Write-Host ""
Write-Host "------------------------------------"
Write-Host "Your current HA Admission Control is set to : $($HAAdmissionControlInfo.HAAdmissionControlEnabled)"
Write-Host "You should have room for another $available vms, while maintaining an HA Failover Level of $($Cluster.HAFailoverLevel) host(s)"
Write-Host ""
write-host "---------------------------------------------------------------------------------"
Write-Host ""

######################
# Process where no VMs
######################
IF ($VMs -eq $null) {
write-host ""
write-host "---------------------------------------------------------------------------------"
write-host "clustername: " $Clustername
$Cluster = Get-Cluster $ClusterName
write-host "cluster: " $Cluster
$ClusterAdv = Get-View $Cluster.Id

$HAAdmissionControlInfo = get-cluster $ClusterName | select *
$vmCPUMinMHz = ($ClusterAdv.configuration.dasconfig.option | Where {$_.Key -eq "das.vmCpuMinMHz"}).Value
If ($vmCPUMinMHz){$MinCPUReservation = $vmCPUMinMHz}
Else {$MinCPUReservation = $DefaultCPURes}
$vmMemoryMinMB = ($ClusterAdv.configuration.dasconfig.option | Where {$_.Key -eq "vmMemoryMinMB"}).Value
If ($vmMemoryMinMB){$MinMemoryReservation = $vmMemoryMinMB}
Else {$MinMemoryReservation = $DefaultMemoryRes}
write-host "There is no VM in this cluster!"

$MaxCPUSlot = $DefaultCPURes
$MaxMemSlot = $DefaultMemoryRes
$myVMobj.CPUSlot = $DefaultCPURes
$myVMobj.MemSlot = $DefaultMemoryRes
$myVMobj.NumCpu = 1

#################
# Process VMHosts
#################
$VMHosts = Get-VMHost -Location $Cluster | Sort-Object Name
$myVMHostCol = @()
$k = 1
$l = $VMHosts.length
ForEach ($VMHost in $VMHosts)
{
$myVMHostObj = "" | Select-Object Name, CPU, CPUSlots, Memory, MemSlots
$myVMHostObj.Name = $VMHost.Name
$VMHostAdv = Get-View $VMHost.Id
$myVMHostObj.CPU = [math]::Round(($VMHostAdv.hardware.cpuinfo.numcputhreads * $VMHostAdv.hardware.cpuinfo.hz / 1000000),0)
$myVMHostObj.CPUSlots = [math]::Floor($myVMHostObj.CPU / $MaxCPUSlot)
$myVMhostObj.Memory = [math]::Round(($VMHostAdv.hardware.memorysize / 1MB),0)
$myVMHostObj.MemSlots = [math]::Floor((($myVMHostObj.Memory)-1600) / $MaxMemSlot)
$myVMHostCol += $myVMHostObj
$k++

##############
# Calculations
##############
$TotalCPUSlots = ($myVMHostCol | Sort-Object CPUSlots | Select-Object -First ($myVMHostCol.Length - $Cluster.HAFailoverLevel) | Measure-Object -Property CPUSlots -Sum).Sum
$TotalMemSlots = ($myVMHostCol | Sort-Object MemSlots | Select-Object -First ($myVMHostCol.Length - $Cluster.HAFailoverLevel) | Measure-Object -Property MemSlots -Sum).Sum
If ($TotalMemSlots -lt $TotalCPUslots){$capacity = $TotalMemSlots}
Else {$capacity = $TotalCPUslots}
$available = ($capacity - $VMs.Length)
}

########
# Output
########
write-host ""
Write-Host "------------------------------------"
Write-Host "In the absence of any VM, the highest CPU usage is set to: $DefaultCPURes"
Write-Host "In the absence of any VM, the highest MEM usage is set to: $DefaultMemoryRes"
write-host ""
Write-Host "------------------------------------"
Write-Host "Your cluster has the following VMHosts:"
$myVMHostCol | Format-Table -AutoSize
Write-Host "If you should lose your heaviest VMHost, you would have left:"
Write-Host " Total Number of CPU slots: $TotalCPUSlots"
Write-Host " Total Number of memory slots: $TotalMemSlots"
write-host ""
Write-Host "------------------------------------"
$MostRestrictiveValue = [math]::Min($TotalCPUSlots,$TotalMemSlots)
Write-Host "vCenter2.5 uses the most restrictive value from above to set the HA Slot Size, that is: $MostRestrictiveValue"
Write-Host ""
Write-Host "------------------------------------"
Write-Host "Your current HA Admission Control is set to : $($HAAdmissionControlInfo.HAAdmissionControlEnabled)"
Write-Host "You should have room for another $available vms, while maintaining an HA Failover Level of $($Cluster.HAFailoverLevel) host(s)"
Write-Host ""
write-host "---------------------------------------------------------------------------------"
Write-Host ""
}

$clusHACapacity."HA Slot Size" = $MostRestrictiveValue
$clusHACapacity."HA Admission Control Status" = $($HAAdmissionControlInfo.HAAdmissionControlEnabled)
$clusHACapacity."HA FailOver Level of 'x' Host(s)" = ($Cluster.HAFailoverLevel)
$clusHACapacityInfo += $clusHACapacity
}
}
}

If (($clusHACapacityInfo | Measure-Object).count -gt 0) {
$MyReport += Get-CustomHeader "HA Slot Size for Version 3 Environments" "The following calculates the HA Slot Size for a Version 3 Environment"
$MyReport += Get-HTMLTable $clusHACapacityInfo
$MyReport += Get-CustomHeaderClose
}

DISCLAIMER. THIS INFORMATION IS PROVIDED TO YOU “AS IS” WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN, EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE AND SHALL NOT BE LIABLE FOR ANY DAMAGES ARISING OUT OF OR IN CONNECTION WITH THE USE OF THIS CONTENT, INCLUDING DIRECT, INDIRECT, CONSEQUENTIAL DAMAGES, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

About these ads
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s