Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 177014

Re: Need help to create Capacity Planning script.

$
0
0

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-formatd
$i=0
$ClustNum=0
$clusters=Get-Cluster
$ClusterCount=$clusters.count
$openfile= @()
$OutputFile="C:\Temp\ClusterStats.csv"

FunctionMin_Max_Avg ($E, $C, $S) {
Get-Stat-Entity$E-Stat$C-Start$S |
Group-Object-Property {$_.Entity.Name} | %{
 
$stats=$_.Group | Measure-Object-PropertyValue-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-eq0) {$RemainingSlots=0}
  
else
  {
$RemainingSlots=$TotalSlots-$UsedSlots}

$ClusterNumVcpu=0

foreach($VMin$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-eq0) {$VcpuRatio=0}
  
elseif ($ClusterCores-eq$null) {$VcpuRatio=0}
  
else{$VcpuRatio =[Math]::Round(($ClusterNumVcpu/$ClusterCores),2)}


if ($ClusterCores-eq0) {$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=""
######################################################







Viewing all articles
Browse latest Browse all 177014

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>