VMware Cloud Community
VM_
Contributor
Contributor

Need help to create Capacity Planning script.

Hi All,

We have vCops and I really how I can produce capacity and Performance graphs with a few clicks. However my manager has decided that he would rather present capacity planning data using excel Smiley Sad. Therefore he has asked for the following data to be output into a .csv and for additional data to be appended to it once a month. Also wants to know if we can get the last 6 months of data too.

For each cluster (10 samples for each per month)

Number of Hosts per cluster

Virtual Machines Count

ClusterCPUCores           

ClusterAllocatedvCPUs      

ClustervCPUpCPURatio      

ClusterEffectiveMemoryGB   

ClusterAllocatedMemoryGB

Monthly Average Ready %

Average CPU Usage of VMs

Average CPU usage of hosts

Average Memory Usage of Hosts

At the moment I can compile this data from multiple sources but it so slow and manual.

Any help appreciated.

Cheers.

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

Perhaps this can help Connecting to vCOps using PowerCli

Mind, it's unsupported!


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

Reply
0 Kudos
VM_
Contributor
Contributor

Hey,

Thanks for details. Do you think this is achieable running a script against virtual center.

Cheers,

Reply
0 Kudos
LucD
Leadership
Leadership

Do you mean if you can produce such a report without using the vCops data and just with the metrics available from vCenter ?

If yes, that is possible.

Note that it of course depends how long your vCenter keeps the performance metrics in it's database.

And take note of the aggregation jobs. After some time, you will only have 1 metric value for 1 day, that means you will have to run the script on a regular basis (when the finer grained metric data is still available).


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

Reply
0 Kudos
VM_
Contributor
Contributor

I need to re-define the requirements then:

For each cluster (Run once at the end of each month and expect a single result for each).

Number of Hosts per cluster

Virtual Machines Count

ClusterCPUCores          

ClusterAllocatedvCPUs     

ClustervCPUpCPURatio     

ClusterEffectiveMemoryGB  

ClusterAllocatedMemoryGB

Monthly Average Ready %

Average CPU Usage of VMs

Average CPU usage of hosts

Average Memory Usage of Hosts

Do you have any scripts that will get me started and I can take it from there. Will revert with progress.

Thanks.

Reply
0 Kudos
LucD
Leadership
Leadership

Those last 4 can be retrieved with Get-Stat.

But should the others be the value at the moment you run the script ?


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

Reply
0 Kudos
michaelbrux
Contributor
Contributor

I can help with a bit of this script. I'll take a look tomorrow and modify one that I have developed.  Not sure how you capture average Ready or what use that would be at the cluster lever.  Also please clarify the following points

Average CPU Usage of VMs

Average CPU usage of hosts

Average Memory Usage of Hosts

If this is a cluster lever report I think it makes sense to collect  only

Average CPU usage of cluster

Average Memory Usage of cluster

Reply
0 Kudos
michaelbrux
Contributor
Contributor

Here is the script that I have.  It doesn't contain ClusterEffectiveMemoryGB,  ClusterAllocatedMemoryGB or Monthly Average Ready %.  The memory stats should be fairly easy to add.  It also includes quite a few fields that are not in your requirements, but you can just delete them.  The script is meant to collect history so the output file does not get overwritten the second, third time that the script is run. 

$csvreport = @()
$start = (Get-Date).AddMonths(-1)
$today=Get-Date -format d
$i=0
$ClustNum=0
$clusters=Get-Cluster
$ClusterCount=$clusters.count
$openfile = @()
$OutputFile="C:\Temp\ClusterStats.csv"

Function Min_Max_Avg ($E, $C, $S) {
Get-Stat -Entity $E -Stat $C -Start $S |
Group-Object -Property {$_.Entity.Name} | %{
 
$stats = $_.Group | Measure-Object -Property Value -Average -Maximum -Minimum

  
$Avg = [math]::round(($stats.Average), 0)
  
$Min = [math]::round(($stats.Minimum), 0)
  
$Max = [math]::round(($stats.Maximum), 0)
Return $Avg,$Min,$Max }

#check for file -Read old file if exists
if (Test-Path $OutputFile){
$csvreport=type $OutputFile | ConvertFrom-Csv
}

Get-Cluster | Foreach-object {
$entity = $_
$cluster=$_  
$ClustNum++

#Progress Bar
$Activity="Collecting Stats for Cluster"
Write-Progress -Activity "Collecting stats for cluster $entity"  -Status "Cluster $ClustNum of $ClusterCount" -PercentComplete (($i/$ClusterCount)*100)

#CPU Min Max and Average
$counter = "cpu.usage.average"
$Cpu_Avg,$Cpu_Min,$Cpu_Max= Min_Max_Avg $entity $counter $start

#Memory Min Max and Average
$counter="mem.usage.average"
$Mem_Avg,$Mem_Min,$Mem_Max= Min_Max_Avg $entity $counter $start


$VMHosts = Get-Cluster $cluster | Get-VMHost
$VMs = Get-Cluster $cluster | Get-VM
$ClusterCores=$cluster.ExtensionData.Summary.NumCpuCores
$TotalSlots=$cluster.HATotalSlots
$UsedSlots=$cluster.HAUsedSlots
If ($TotalSlots -eq 0) {$RemainingSlots=0}
  
else
  {
$RemainingSlots=$TotalSlots - $UsedSlots}

$ClusterNumVcpu=0

foreach($VM in $VMs) {
$ClusterNumVcpu+=$VM.NumCpu
}


#Calculate average VM per host
If ($VMhosts.Count  -eq $null) {$AverageVMs=0}
else
  { 
$AverageVMs = [math]::round(($VMs.count / $VMHosts.count), 0)}

#Calculate Vcpu Ratio
if ($ClusterCores -eq 0) {$VcpuRatio=0}
  
elseif ($ClusterCores -eq $null) {$VcpuRatio=0}
  
else{$VcpuRatio =[Math]::Round(($ClusterNumVcpu/$ClusterCores),2)}


if ($ClusterCores -eq 0) {$VMsPerCore =0}
elseif ($ClusterCores -eq $null) {$VMsPerCore =0}
else {$VMsPerCore=[Math]::round(($VMs.Count /$ClusterCores),0)}

# Creates List of Custer Details
$clusterdetails = "" |select-object Collection_Date,Cluster_Name,Host_Count,VM_Count,
  Average_VM_Per_Host,Cluster_Cores,Cluster_Vcpu,Vcpu_Ratio,
  VMs_Per_Core,Total_Slots,Used_Slots,Remaining_Slots,
  CPU_MAX,CPU_MIN,CPU_AVG,MEM_MAX,MEM_MIN,MEM_AVG
 
$clusterdetails.Collection_Date=$today
$clusterdetails.Cluster_Name = $cluster.Name

if ($VMhosts.Count  -eq $null) {$clusterdetails.Host_Count =0}
  
else$clusterdetails.Host_Count =$VMHosts.Count}

if ($VMs.Count  -eq $null) {$clusterdetails.VM_Count =0}
  
else {$clusterdetails.VM_Count=$VMs.Count}

$clusterdetails.Average_VM_Per_Host=$AverageVMs
$clusterdetails.Cluster_Cores=$ClusterCores
$clusterdetails.Cluster_Vcpu=$ClusterNumVcpu
$clusterdetails.Vcpu_Ratio=$VcpuRatio
$clusterdetails.VMs_Per_Core=$VMsPerCore
$clusterdetails.Total_Slots=$TotalSlots
$clusterdetails.Used_Slots=$UsedSlots
$clusterdetails.Remaining_Slots =$RemainingSlots
$clusterdetails.CPU_MAX=$Cpu_Max
$clusterdetails.CPU_MIN=$Cpu_Min
$clusterdetails.CPU_AVG=$Cpu_Avg
$clusterdetails.MEM_MAX=$Mem_Max
$clusterdetails.MEM_MIN=$Mem_Min
$clusterdetails.MEM_AVG=$Mem_Avg

$i++
$csvreport += $clusterdetails
}

$csvreport |export-csv -NoTypeinformation $OutputFile
$csvreport = ""
######################################################






Reply
0 Kudos