VMware Cloud Community
SithL0rd
Contributor
Contributor

Cluster reporting

  I have to get an overall vsphere report out to my boss by monday. I am looking to report on the following cluster metrics, i would like to run this per cluster. i can get some these metrics by using one-liners. I am struggling with putting it all together in one script and export it to a csv file.

- Total Memory

- Total Cpus (number of cores if possible)

- Cluster CPU usage average

- Cluster Memory usage average

- Host CPU usage average

- Host Memory usage average

- VM's perhost

- Datastore Usage datastore name, available gb, capacity gb, & percent used

- Vm's & hosts that average over 75 percent of cpu & memory

Any help would be appreciated.

0 Kudos
5 Replies
LucD
Leadership
Leadership

You have 2 main options, one is to use the Select-Object cmdlet with calculated properties.

Get-Cluster |

Select Name,

@{N="TotalCpu";E={Get-VMHost -Location $_ | Measure-Object -Property NumCpu -Sum | Select -ExpandProperty Sum}},

...

The other is to create an object and assign the values to the properties of that object.

Get-Cluster | %{

     New-Object PSObject -Property @{

          Name = $_.Name

          TotalCpu = ....

     }

}

Let me know if there are any properties you have a hard time finding.


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

0 Kudos
SithL0rd
Contributor
Contributor

actually i have the datastore script in place, after digging through some of my files i found one you helped me out with a while ago. Can look over the syntax and see if it looks good?

Get-VMHost |
ForEach-Object {
  $VMHost = $_
  $VMHost | Get-Datastore |
  Select-Object -Property @{N="VMHost";E={$VMHost.Name}},
  @{N="Datastore";E={$_.Name}},
  CapacityGB,@{N="ConsumedGB";E={$_.CapacityGB-$_.FreeSpaceGB}},
  @{N="ConsumedPercentage";E={[int](100*($_.CapacityGB-$_.FreeSpaceGB)/$_.CapacityGB)}}
}
Get-VMHost |
ForEach-Object {
  $VMHost = $_
  $Datastores = $VMHost | Get-Datastore
  $TotalCapacityGB = ($Datastores | Measure-Object -Property CapacityGB -Sum).Sum
  $TotalFreeSpaceGB = ($Datastores | Measure-Object -Property FreeSpaceGB -Sum).Sum
  $TotalConsumedSpaceGB = $TotalCapacityGB - $TotalFreeSpaceGB
  $TotalConsumedPercentage = [int](100*($TotalConsumedSpaceGB)/$TotalCapacityGB)
  $VMHost | Select-Object -Property Name,MemoryUsageGB,CpuUsageMhz,MemoryTotalGB,NumCpu,Version,
  @{N="VM's Managed";E={[string]::Join(',',($_ | Get-VM).Name)}},
  @{N="TotalCapacityGB";E={$TotalCapacityGB}},
  @{N="TotalConsumedSpaceGB";E={$TotalConsumedSpaceGB}},
  @{N="TotalConsumedPercentage";E={$TotalConsumedPercentage}}
}

what would be the best way to apply this to getting the averages of memory & cpu on a cluster?

And how can i apply this to getting a measurement of all members of a cluster esxi hosts and vm's utlizing over 75% of its resources?  i assume measure-object would be involved, just unsure of the context and how to best use it.

0 Kudos
LucD
Leadership
Leadership

Those 2 scripts will report on VMhosts and datastores, but not clusters.

To find hosts and VMs using resources over a specific threshold, you will need to fetch the metric cpu.usage.average and mem.usage.average.

These metrics return percentages fro which you test if they are over a specific threshold


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

0 Kudos
chinsjain
Contributor
Contributor

Hi mate, can you please help me with the commands to pull out reports for the below metrics as you mentioned. A consolidated script is good but I am fine with individual commands or scripts also.

- Total Memory

- Total Cpus (number of cores if possible)

- Cluster CPU usage average

- Cluster Memory usage average

- Host CPU usage average

- Host Memory usage average

- VM's perhost

- Datastore Usage datastore name, available gb, capacity gb, & percent used

- Vm's & hosts that average over 75 percent of cpu & memory

I need to have some data captured as soon as possible,

Appreciate your help.

Thanks

0 Kudos
kunaludapi
Expert
Expert

Try this, for last point you can do filtering within CSV/excel. (I can do filtering in the powershell, want you to have all the reports), Red marked is the path where your CSV files generated.

### Cluster inforamation

Get-Cluster | foreach {

    $ClusterReport = "" | Select-Object ClusterName, ClusterMemory, ClusterCPUSockets, ClusterCPUcores, "ClusterCPUAvgUse(%)", "ClusterMemAvgUse(%)"

    $ClusterReport.ClusterName = $_.Name

    $ClusterReport.ClusterMemory = [Math]::Round($_.ExtensionData.summary.TotalMemory / 1GB)

    $HostCPUCount = 0

    $HostCPUCoreCount = 0

    foreach ($VMhostid in $_.ExtensionData.host) {

        $VMhost = Get-VMHost -Id $vmhostid

        $HostCPU = $vmhost.ExtensionData.Summary.Hardware.NumCpuPkgs

        $HostCPUcore = $vmhost.ExtensionData.Summary.Hardware.NumCpuCores/$HostCPU

        $HostCPUCount = $HostCPU + $HostCPUCount

        $HostCPUCoreCount = $HostCPUcore + $HostCPUCoreCount

    }

    $ClusterReport.ClusterCPUSockets = $HostCPUCount

    $ClusterReport.ClusterCPUcores = $HostCPUCoreCount

    $CpuStats = $_ | Get-Stat -stat cpu.usage.average | Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average

    $ClusterReport."ClusterCPUAvgUse(%)" = [Math]::Round($CpuStats)

    $CpuStats = $_ | Get-Stat -stat mem.usage.average | Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average

    $ClusterReport."ClusterMemAvgUse(%)" = [Math]::Round($CpuStats)

    $ClusterReport

} | Export-Csv -NoTypeInformation  -Path c:\temp\clusterinfo.csv

### Host Inforamation

Get-VMHost | foreach {

    $hostreport =  "" | Select-Object Hostname, ClusterName, "HostCPUAvgUse(%)", "HostMemAvgUse(%)", VMs

    $hostreport.Hostname = $_.Name

    $hostreport.ClusterName = $_ | Get-Cluster | Select-Object -ExpandProperty Name

    $CpuStats = $_ | Get-Stat -stat cpu.usage.average | Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average

    $hostreport."HostCPUAvgUse(%)" = [Math]::Round($CpuStats)

    $CpuStats = $_ | Get-Stat -stat mem.usage.average | Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average

    $hostreport."HostMemAvgUse(%)" = [Math]::Round($CpuStats)

    $hostreport.VMs = $($_ | Get-VM).count

    $hostreport

} | Export-Csv -NoTypeInformation -Path C:\temp\VMhostinfo.csv

### Datastore Inforamation

Get-Datastore | Select-Object Name, FreeSpaceGB, CapacityGB, @{N="%Used"; E={[math]::round($_.FreeSpaceGB / $_.CapacityGB * 100)}} | Export-Csv -NoTypeInformation -Path C:\temp\datastoreinfo.csv

### VM and host Stat Inforamation

Get-VM | Where-Object {$_.PowerState -eq "Poweredon"} |Select-object Name, @{N="CPUavg"; E={$_ | Get-Stat -stat cpu.usage.average | Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average}}, @{N="Memavg"; E={$_ | Get-Stat -stat Mem.usage.average | Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average}} | Export-Csv -NoTypeInformation -Path C:\temp\VMstats.csv

Get-VMHost | Select-object Name, @{N="CPUavg"; E={$_ | Get-Stat -stat cpu.usage.average | Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average}}, @{N="Memavg"; E={$_ | Get-Stat -stat Mem.usage.average | Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average}} | Export-Csv -NoTypeInformation -Path C:\temp\esxistats.csv

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos