VMware Cloud Community
Sivaramsharmar
Enthusiast
Enthusiast

Available Cluster Slots Based on VM past few days

Hi All,

Is there any way to get Available Slots for CPU, Memory & DataStore in a Cluster based on VM Performance from past few days

Below Script will capture the Avg CPU,RAM & Datastore usage for past few days.

I need to get the available CPU , MEM & DataStore Slots based on these report.

Please suggest.

$cluster = get-cluster

foreach($cl in $cluster){

$vms = $cl | get-vm

$avgvmcpuusage = get-stat -entity ($vms) -maxsamples 1000 -stat cpu.usagemhz.average -erroraction "silentlycontinue"

$avgvmcpuusage = $avgvmcpuusage | measure-object -property value -average

$avgvmcpuusage = $avgvmcpuusage.average

$avgvmcpuusage = [int]$avgvmcpuusage

$TotalVMMemoryGB = $VMs  | Measure-Object -Property MemoryGB -Sum

$TotalVMMemoryGB = $TotalVMMemoryGB.Sum

$TotalVMMemoryGB = $TotalVMMemoryGB / 1024

$avgVMMemoryGB = [int]$TotalVMMemoryGB/ $vms.count

$TotalVMProvisionedSpaceGB = $VMsTemp | Measure-Object -Property ProvisionedSpaceGB -Sum

$TotalVMProvisionedSpaceGB = $TotalVMProvisionedSpaceGB.Sum -as [int]

$VMAverageDatastoreUsage =[int]($TotalVMProvisionedSpaceGB / $VMs.count)

}

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Slot size calculation is normally based on maximum cpu and memory reservation.

Are you intending to calculate slots on the maximum of the average cpu and memory utilisation over a couple of days ?

What would be the point of that ?

Or are you trying to find over-committed VMs ?


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

Reply
0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Lucd,

Here are the answer's

"Slot size calculation is normally based on maximum cpu and memory reservation."


I hope if I am not wrong HA knows only slots it doesn't know about available resources. Please correct me if I am wrong.


I have written below script to get available resources in a cluster

#CPU Available in Cluster

$cputotal =  Get-Cluster clustername | Get-VMHost | Measure-Object -Property CpuTotalMhz -Sum

$cpuused = Get-Cluster clustername  | Get-VMHost | Measure-Object -Property CpuUsageMhz -Sum

$cpufree = $cputotal - $cpuused

$cpureserved = get-cluster clustername | get-vmhost | get-vm | get-view | select Name,@{N='CPUReservation';E={$_.Config.Cpuallocation.reservation}}| Measure-Object -Property CPUReservation -Sum

$cpuavailable = $cpufree - $cpureserved.sum

#Memory Available in Cluster

$memtotal = get-cluster clustername | get-vmhost | measure-object -property memoryTotalGB -sum

$memused = get-cluster clustername | get-vmhost | measure-object -property memoryusedGB -sum

$memfree = $memtotal - $memused

$memreserved = Get-Cluster clustername | Get-VM | Get-View | select Name,@{N='MemoryReservation';E={$_.config.memoryallocation.reservation}} | Measure-Object -Property MemoryReservation -Sum

$memavailable = $memfree - $memreserved.sum

#DataStore Available in Cluster

$DSTotal = Get-Cluster clustername | Get-Datastore | Measure-Object -Property CapacityGB -Sum

$DSFree = Get-Cluster clustername | Get-Datastore | Measure-Object -Property FreeSpaceGB -Sum

$DSUsed = $DSTotal- $DSFree

$DSReserved = Get-Cluster clustername | Get-VM | Get-HardDisk | where{$_.Storageformat -like "*thick*"} | Measure-Object -Property CapacityGB -Sum

$DSReserved = $DSReserved.sum

$DSAvailable = $DSFree - $DSReserved

"Are you intending to calculate slots on the maximum of the average cpu and memory utilisation over a couple of days ?"

I need to get Available slots of CPU, Memory, Datastore in a cluster based on VM usage over a couple of days.

"What would be the point of that ? Or are you trying to find over-committed VMs ? "

Our Motto is to get report like,

In a production cluster how many VM's we can deploy based on Grade of a VM with resect to current availability of resources , Based on Utilization of VM's over a couple of days.

EX: Configuration of VM's Grade

Grade 1 : vCPU - 2 , Memory in GB - 1 , HDD - 20 GB

Grade 2 : vCPU - 4 , Memory in GB - 2 , HDD - 40 GB

Grade 3 : vCPU - 6 , Memory in GB - 4 , HDD - 60 GB

Output:

Grade 1 VM's - 30

Grade 2 Vm's - 20

Grade 3 VM's -10

If we can't get output by fetching VM's utilization over couple of days then we need to get based on current availablity of CPU,MEM and Datastore how many VM's can be deployed based on Grade of VM.

Please suggest.

Reply
0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Lucd,

I got script from PowerCLI script for vSphere capacity planning and in that script I am trying to get only Cluster Available Slots, But I am not getting actual available slots for the cluster which I am executing. More over is there any way to get the slot size of CPU,Memory and Datastore so that I can able to get my desired result. Please suggest.

pastedImage_2.png

Function GetCPUSlotsAvailable ($VMHostsInClusterTemp, $ClusterVMAverageCPUUsageTemp) {

   

    $VMHostsTotalCPUMhz = $VMHostsInClusterTemp | Measure-Object -Property CpuTotalMhz -Sum

    $VMHostsUsedCPUMhz = $VMHostsInClusterTemp | Measure-Object -Property CpuUsageMhz -Sum

    $VMHostsTotalCPUMhz = $VMHostsTotalCPUMhz.Sum * 0.90 # Keep 10% available for best practice

    $VMHostsUsedCPUMhz = $VMHostsUsedCPUMhz.Sum

    $VMHostsAvailableCPUMhz = $VMHostsTotalCPUMhz - $VMHostsUsedCPUMhz

    $ClusterCPUSlots = $VMHostsAvailableCPUMhz / $ClusterVMAverageCPUUsageTemp # The rest divided by 1 CPU Slot

    $ClusterCPUSlots = [system.math]::floor($ClusterCPUSlots) # Round down

    return $ClusterCPUSlots

}

Function GetMemorySlotsAvailable ($VMHostsInClusterTemp, $ClusterVMAverageMemoryUsageTemp) {

   

    $VMHostsTotalMemoryMB = $VMHostsInClusterTemp | Measure-Object -Property MemoryTotalMB -Sum

    $VMHostsUsedMemoryMB = $VMHostsInClusterTemp | Measure-Object -Property MemoryUsageMB -Sum

    $VMHostsTotalMemoryMB = $VMHostsTotalMemoryMB.Sum * 0.90 # Keep 10% available for best practice

    $VMHostsUsedMemoryMB = $VMHostsUsedMemoryMB.Sum

    $VMHostsAvailableMemoryMB = $VMHostsTotalMemoryMB - $VMHostsUsedMemoryMB

    $ClusterMemorySlots = $VMHostsAvailableMemoryMB / $ClusterVMAverageMemoryUsageTemp # The rest divided by 1 Memory Slot

    $ClusterMemorySlots = [system.math]::floor($ClusterMemorySlots) # Round down

    return $ClusterMemorySlots

}

Function GetDatastoreSlotsAvailable ($DatastoresInClusterTemp, $ClusterVMAverageMemoryUsageTemp) {

   

    # Remove 5% of Datastore capacity for Best Practices

    $DatastoreCapacityTemp = $DatastoresInClusterTemp | Measure-Object -Property CapacityMB -Sum

    $DatastoreCapacityMinus5Percent = $DatastoreCapacity.Sum * 0.95

    $5PercentOfDatastoreCapacity = $DatastoreCapacity.Sum - $DatastoreCapacityMinus5Percent

    $DatastoreFreeSpaceMB = $DatastoreFreeSpaceMB - $5PercentOfDatastoreCapacity

   

    $DatastoreFreeSpaceMB = $DatastoresInClusterTemp | Measure-Object -Property FreeSpaceMB -Sum

    $DatastoreFreeSpaceMB = $DatastoreFreeSpaceMB.Sum / 1024 # Divide by 1024 to convert from MB to GB

    $DatastoreFreeSpaceMB = $DatastoreFreeSpaceMB - $5PercentOfDatastoreCapacity # Keep 5% available for best practice

    $ClusterDatastoreSlots = $DatastoreFreeSpaceMB / $ClusterVMAverageMemoryUsageTemp # Divided by 1 Memory Slot

    $ClusterDatastoreSlots = [system.math]::floor($ClusterDatastoreSlots) # Round down

    return $ClusterDatastoreSlots

}

Function GetVMProvisioningPotential ($CPUSLOTS, $MEMORYSLOTS, $DATASTORESLOTS) {

   

    if ($CPUSLOTS -le $MEMORYSLOTS -and  $CPUSLOTS -le $DATASTORESLOTS){ return ([String]$CPUSLOTS + ". CPU is your limiting factor.")}

    if ($MEMORYSLOTS -le $CPUSLOTS -and  $MEMORYSLOTS -le $DATASTORESLOTS){ return ([String]$MEMORYSLOTS + ". Memory is your limiting factor.")}

    if ($DATASTORESLOTS -le $CPUSLOTS -and  $DATASTORESLOTS -le $MEMORYSLOTS){ return ([String]$DATASTORESLOTS + ". Datastore Disk Space is your limiting factor.")}

   

}

Reply
0 Kudos
LucD
Leadership
Leadership

The way vCenter calculates the slots is briefly documented in KB1010594.

Simplified it takes the maximum CPU and memory reservations of all powered on VMs (if there are no VMs with reservations the algorithm takes a default value).

Those values are kept in the ClusterDasFailoverLevelAdvancedRuntimeInfoSlotInfo object.

This is what you also see in the HA Advanced Runtime Info window (your screenshot).

Alan has a post where he shows how to calculate the slots in the same way as the vCenter does.

See his HA Slot Size Information post.

Equally interesting is Alan's follow up post on how to determine which of your VMs set the slotsizes.

See Which VMs set your Slot Size ?

What I don't understand is how you are trying to calculate slot sizes and available slots based on performance statistics.

Unless you are using the statistics to monitor changes over time in the reservations you have assigned to your VMs.

The script you attached is doing something else than calculate slots, it calculates capacity.

In brief it takes the total available resources for CPU, memory and datastore space, and then calculates how much of these resources is used.

Then it takes the average resource consumption of the VMs in the cluster, and based on those figures, it determines how many "average" VMs you can start additionally in the HA cluster.

This, although the author calls it slots, are not slots in the sense used by vSphere HA.

And hence my confusion on the original question on using Get-Stat to calculate HA slots.


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

Reply
0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Lucd,

Now I clearly understood about HA slot sizes and Slot Sizes cannot be calculated by considering VM usage over a couple of days.

So Now what I have did is I have colleced HA Available slots in single clulster, Slot size for No. of vCPU & Memory.

As Datastore slots we can't get it from cluster so I have using Datastore as a slot only to get Number of VM's can be Hosted in a cluster based on VM Configuration. I am  using only one datastore in a cluster, is there any way that we will be getting output number of VM's based on each datastore in a cluster as well.

Please validate the below script and suggest.

#HA Available Slots(CPU & Memory) in Cluster

$HAAvailableSlots = (Get-Cluster clustername).HAAvailableSlots

$HATotalSlots = (Get-Cluster clustername).HATotalSlots

#DataStore Available

$DSTotal = (Get-Cluster clustername | Get-Datastore  DataStoreName | Measure-Object -Property CapacityMB -Sum).sum

$DSFree = (Get-Cluster clustername | Get-Datastore  DataStoreName | Measure-Object -Property FreeSpaceMB -Sum).sum

$DSUsed = $DSTotal- $DSFree

$DSReserved = (Get-Cluster clustername | Get-VM | Get-HardDisk | where{$_.Storageformat -like "*thick*"} | Measure-Object -Property CapacityGB -Sum).sum

$DSReserved = $DSReserved * 0.05  # Reserving 5 % of DiskSpace

$DSAvailable = $DSFree - $DSReserved

#HA Slots sizes on Each Slot

$HACPUSLOT = (Get-Cluster clustername).HASlotNumVCpus

$HAMEMSLOT = (Get-Cluster clustername).HASlotMemoryMb

$DATASTORE = [int]$DSAvailable

$TotalHASlots = $HAAvailableSlots

$slotsizecpu = $HACPUSLOT

$slotsizemem = $HAMEMSLOT

$slotsizeds = 20480 # Assuming with mininum of 20GB HDD only for getting Number of VM's to be hosted based on Grade's

$s1cpu = 2      #Grade 1 VM,No. Of vCPU's

$s1mem = 2048 #Grade 1 VM,Memory in MB

$s1ds = 20480 #Grade 1 VM,DataStore in MB

$s2cpu = 4 #Grade 2 VM,No. Of vCPU's

$s2mem = 4096 #Grade 2 VM,Memory in MB

$s2ds = 40960 #Grade 2 VM,DataStore in MB

$s3cpu = 8 #Grade 3 VM,No. Of vCPU's

$s3mem = 8192 #Grade 3 VM,Memory

$s3ds = 81920 #Grade 3 VM,DataStore

$s1cc = $s1cpu/$slotsizecpu #Grade1 vCPu / SlotSize CPU

$s1mc = $s1mem/$slotsizemem

$s1dc = $s1ds/$slotsizeds

$s2cc = $s2cpu/$slotsizecpu

$s2mc = $s2mem/$slotsizemem

$s2dc = $s2ds/$slotsizeds

$s3cc = $s3cpu/$slotsizecpu

$s3mc = $s3mem/$slotsizemem

$s3dc = $s3ds/$slotsizeds

$ts1cc = $TotalHASlots/$s1cc

$ts1mc = $TotalHASlots/$s1mc

$ts1dc = $DATASTORE/$s1dc

$ts2cc = $TotalHASlots/$s2cc

$ts2mc = $TotalHASlots/$s2mc

$ts2dc = $DATASTORE/$s2dc

$ts3cc = $TotalHASlots/$s3cc

$ts3mc = $TotalHASlots/$s3mc

$ts3dc = $DATASTORE/$s3dc

write-output "HA Total Slots :$HATotalSlots"

write-output "HA Available Slots :$HAAvailableSlots "

write-output "Grade1 : vCPU - $ts1cc,MEM - $ts1mc, DataStore - $ts1dc"

write-output "Grade1 : vCPU - $ts2cc,MEM - $ts2mc, DataStore - $ts2dc"

write-output "Grade1 : vCPU - $ts2cc,MEM - $ts3mc, DataStore - $ts3dc"

$Grade1 = [array]($ts1cc,$ts1mc,$ts1dc)

$grade1 = [int]($Grade1 | Measure-Object -Minimum).minimum

Write-output "Number of VM's $grade1 we can Host in Grade1"

$Grade2 = [array]($ts2cc,$ts2mc,$ts2dc)

$grade2 = [int]($Grade2 | Measure-Object -Minimum).minimum

Write-output "Number of VM's $grade2 we can Host in Grade2"

$Grade3 = [array]($ts3cc,$ts3mc,$ts3dc)

$grade3 = [int]($Grade3 | Measure-Object -Minimum).minimum

Write-output "Number of VM's $grade3 we can Host in Grade3"

Reply
0 Kudos