Hi,
Looking for a script that would produce a .csv file to report the following at the cluster level.
ClusterName | CPU total | CPU Granted | CPU Avail | CPU avail % | Mem Total | Mem Granted | Mem Avail | Mem avail % | Storage Total | Strorage Granted | Storage Avail | Strorage avail % |
See attached .xls
Is this possible?
Your assistance is greatly appreciated.
I think the following script will give what you want.
$report = @() Get-Cluster | Get-View | % { $row = "" | Select ClusterName, CPUTotGHz, CPUGrantGHz, CPUAvailGHz, CPUAvailperc, MemTotMb, MemGrantMb, MemAvailMb, Memavailperc, StorTotGb, StorGrantGb, StorAvailGb, Storavailperc $row.ClusterName = $_.Name $row.CPUTotGHz = "{0:f1}" -f ($_.Summary.TotalCpu / 1Kb) $row.CPUGrantGHz = "{0:f1}" -f ($_.Summary.EffectiveCpu / 1Kb) $row.CPUAvailGHz = "{0:f1}" -f (($_.Summary.TotalCpu - $_.Summary.EffectiveCpu) / 1Kb) $row.CPUAvailPerc = "{0:f2}" -f (($_.Summary.TotalCpu - $_.Summary.EffectiveCpu) / ($_.Summary.TotalCpu) * 100) $row.MemTotMb = "{0:f1}" -f ($_.Summary.TotalMemory / 1Mb) $row.MemGrantMb = "{0:f1}" -f ($_.Summary.EffectiveMemory ) $row.MemAvailMb = "{0:f1}" -f (($_.Summary.TotalMemory / 1Mb)- $_.Summary.EffectiveMemory) $row.MemAvailPerc = "{0:f2}" -f ((($_.Summary.TotalMemory / 1Mb)- $_.Summary.EffectiveMemory) / ($_.Summary.TotalMemory / 1Mb) * 100 ) # Datastores $dsTotalCapacity = 0 $dsTotalFree = 0 foreach($dsMoRef in $_.Datastore){ $ds = Get-View -Id $dsMoRef if($ds.Summary.Type -ne "VMFS"){continue} $dsTotalCapacity += $ds.Summary.Capacity $dsTotalFree += $ds.Summary.FreeSpace } $row.StorTotGb = "{0:f1}" -f ($dsTotalCapacity / 1Gb) $row.StorGrantGb = "{0:f1}" -f (($dsTotalCapacity - $dsTotalFree) / 1Gb) $row.StorAvailGb = "{0:f1}" -f ($dsTotalFree / 1Gb) $row.StorAvailPerc = "{0:f2}" -f ($dsTotalFree / $dsTotalCapacity * 100) $report += $row } $report | Export-Csv "C:\report-cluster.csv" -NoTypeInformation
Note1: for the datastore figures I exclude the non-VMFS datastores. If you want to see these as well in the figures remove the line "if($ds.Summary.Type -ne "VMFS")"
Note2: the CPU and memory figures you get are corresponding with what you see in the VIC under the tab for a cluster. Note that you could also look at the "effective" CPU and memory resources used. See for a sample of this.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What exactly do you need in the Storage columns ?
The total of all available space on the datastores in the cluster ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Yes.
The healthcheck output should be just one line for each column heading.
Basically a quick view of the Cluster.
I think the following script will give what you want.
$report = @() Get-Cluster | Get-View | % { $row = "" | Select ClusterName, CPUTotGHz, CPUGrantGHz, CPUAvailGHz, CPUAvailperc, MemTotMb, MemGrantMb, MemAvailMb, Memavailperc, StorTotGb, StorGrantGb, StorAvailGb, Storavailperc $row.ClusterName = $_.Name $row.CPUTotGHz = "{0:f1}" -f ($_.Summary.TotalCpu / 1Kb) $row.CPUGrantGHz = "{0:f1}" -f ($_.Summary.EffectiveCpu / 1Kb) $row.CPUAvailGHz = "{0:f1}" -f (($_.Summary.TotalCpu - $_.Summary.EffectiveCpu) / 1Kb) $row.CPUAvailPerc = "{0:f2}" -f (($_.Summary.TotalCpu - $_.Summary.EffectiveCpu) / ($_.Summary.TotalCpu) * 100) $row.MemTotMb = "{0:f1}" -f ($_.Summary.TotalMemory / 1Mb) $row.MemGrantMb = "{0:f1}" -f ($_.Summary.EffectiveMemory ) $row.MemAvailMb = "{0:f1}" -f (($_.Summary.TotalMemory / 1Mb)- $_.Summary.EffectiveMemory) $row.MemAvailPerc = "{0:f2}" -f ((($_.Summary.TotalMemory / 1Mb)- $_.Summary.EffectiveMemory) / ($_.Summary.TotalMemory / 1Mb) * 100 ) # Datastores $dsTotalCapacity = 0 $dsTotalFree = 0 foreach($dsMoRef in $_.Datastore){ $ds = Get-View -Id $dsMoRef if($ds.Summary.Type -ne "VMFS"){continue} $dsTotalCapacity += $ds.Summary.Capacity $dsTotalFree += $ds.Summary.FreeSpace } $row.StorTotGb = "{0:f1}" -f ($dsTotalCapacity / 1Gb) $row.StorGrantGb = "{0:f1}" -f (($dsTotalCapacity - $dsTotalFree) / 1Gb) $row.StorAvailGb = "{0:f1}" -f ($dsTotalFree / 1Gb) $row.StorAvailPerc = "{0:f2}" -f ($dsTotalFree / $dsTotalCapacity * 100) $report += $row } $report | Export-Csv "C:\report-cluster.csv" -NoTypeInformation
Note1: for the datastore figures I exclude the non-VMFS datastores. If you want to see these as well in the figures remove the line "if($ds.Summary.Type -ne "VMFS")"
Note2: the CPU and memory figures you get are corresponding with what you see in the VIC under the tab for a cluster. Note that you could also look at the "effective" CPU and memory resources used. See for a sample of this.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thank you very much for the quick response.
I'm going to try it out today.