VMware Cloud Community
alias35
Contributor
Contributor

Need assistance getting combined cluster resource utilization for cpu and memory for all clusters within a folder

Hello All,

I am new to Powercli and Powershell and have been trying to develop a script to get utilization statistics.

We have three folders (s1, s2, and s3) in vCenter > Hosts and Clusters that house many different clusters.

The goal of these stats is to show cpu and memory resource allocation for each cluster, then add up all of the clusters in each folder to show overall utilization of resources at the folder level.


To do that we have been adding stats in Excel Sheet like the following.

The table below was pulled from our Excel sheet for all of the clusters in a Folder called S1.

The first table is used to generate the second table of totals.

S1 Clusters     

ClusterNameCPUTotalCapacityCPUReservedCapacityCPUAvailableCapacityMemoryTotalCapacityMemoryReservedMemoryAvailalbleCapacity
clus0165052814270250782619803154077271572588
clus0265052813669251383619795044771111502393
clus0365052818101646951219791768106301168546


S1 Totals    

S1Total CapacityReserved Capacity% utilized
CPU195158444515423%
Mem5938881159165527%

For the past couple weeks I've been I've been researching and have developed this script below.

I know there is probably a must better way to do this.

The problems I'm having:

1. I've found blogs detailing how to pull cluster resource allocation stats like cpu and memory above, however I cannot find a way to do it at the cluster level.

    If the stats cannot be pulled this way and they need to be added up for each cluster, I am not sure how that can be done yet.

2. With what I've written, the output shows the Table Headings over each cluster. I'm unsure how to output the results similar to the first table above.

3. For some reason MemoryAvailableCapacity always shows up blank.

Here is the script.

$cluster01 = Get-Cluster clus01

$cluster02 = Get-Cluster clus02

$cluster03 = Get-Cluster clus03

$rp01 = Get-View $cluster01.ExtensionData.ResourcePool

$rp02 = Get-View $cluster02.ExtensionData.ResourcePool

$rp03 = Get-View $cluster03.ExtensionData.ResourcePool

$row01 = New-Object PSObject -Property @{

"ClusterName"=$cluster01.Name;

"CPUTotalCapacity" = $rp01.Runtime.Cpu.MaxUsage;

"CPUReservedCapacity" = $rp01.Runtime.Cpu.ReservationUsed;

"CPUAvailableCapacity" = $rp01.Runtime.Cpu.MaxUsage - $rp01.Runtime.Cpu.ReservationUsed;

"MemoryTotalCapacity" = $rp01.Runtime.Memory.MaxUsage/1MB;

"MemoryReserved"= $rp01.Runtime.Memory.ReservationUsed/1MB;

"MemoryAvailableCapacity"=($rp01.Runtime.Memory.MaxUsage - $rp01.Runtime.Memory.ReservationUsed)/1MB;

}

$row02 = New-Object PSObject -Property @{

"ClusterName"=$cluster02.Name;

"CPUTotalCapacity" = $rp02.Runtime.Cpu.MaxUsage;

"CPUReservedCapacity"= $rp02.Runtime.Cpu.ReservationUsed;

"CPUAvailableCapacity"=$rp02.Runtime.Cpu.MaxUsage - $rp02.Runtime.Cpu.ReservationUsed;

"MemoryTotalCapacity" = $rp02.Runtime.Memory.MaxUsage/1MB;

"MemoryReserved"= $rp02.Runtime.Memory.ReservationUsed/1MB;

"MemoryAvailableCapacity"=($rp02.Runtime.Memory.MaxUsage - $rp02.Runtime.Memory.ReservationUsed)/1MB;

}

$row03 = New-Object PSObject -Property @{

"ClusterName"=$cluster03.Name;

"CPUTotalCapacity" = $rp03.Runtime.Cpu.MaxUsage;

"CPUReservedCapacity"= $rp03.Runtime.Cpu.ReservationUsed;

"CPUAvailableCapacity"=$rp03.Runtime.Cpu.MaxUsage - $rp03.Runtime.Cpu.ReservationUsed;

"MemoryTotalCapacity" = $rp03.Runtime.Memory.MaxUsage/1MB;

"MemoryReserved"= $rp03.Runtime.Memory.ReservationUsed/1MB;

"MemoryAvailableCapacity"=($rp01.Runtime.Memory.MaxUsage - $rp03.Runtime.Memory.ReservationUsed)/1MB;

}

$row01 | select-Object ClusterName,CPUTotalCapacity,CPUReservedCapacity,CPUAvailableCapacity,MemoryTotalCapacity,MemoryReserved,MemoryAvailalbleCapacity |

Sort-Object -Property Name | Format-Table -AutoSize

$row02 | select-Object ClusterName,CPUTotalCapacity,CPUReservedCapacity,CPUAvailableCapacity,MemoryTotalCapacity,MemoryReserved,MemoryAvailalbleCapacity |

Sort-Object -Property Name | Format-Table -AutoSize


$row03 | select-Object ClusterName,CPUTotalCapacity,CPUReservedCapacity,CPUAvailableCapacity,MemoryTotalCapacity,MemoryReserved,MemoryAvailalbleCapacity |

Sort-Object -Property Name | Format-Table -AutoSize

Attached is a screenshot of the ouptut of the script from the command line.

Any advice or input would be greatly appreciated.

0 Kudos
0 Replies