VMware Cloud Community
pmeqix
Contributor
Contributor
Jump to solution

Cluster Statistics

Hello,

I have the attached cluster report script where I am trying to report following data and need some help in getting the information through the right functions and commands.

This Category names match the overall info represented in VC Client interface

  • Summary Tab
    • General
      • Total CPU Resources
      • Total Memory
      • Number of Hosts
      • Total Processors
        • Number of Sockets --???
        • Number of Cores --???
    • VMware HA
      • Current CPU Failover Capacity
      • Current Memory Failvoer Capacity
      • Configured Failover Capacity
    • VMware DRS
      • Migration Automation Level
      • DRS Recommendations
      • DRS Faults
      • Migration Threshold
      • target hosts load standard deviation
      • Current host load standard deviation
  • Resource Allocation Tab
    • CPU
      • Total Capacity
      • Reserved Capacity
      • Available Capacity
    • Memory
      • Total Capacity
      • Reserved Capacity
      • Available Capacity
  • Performance Tab
    • Hosts View - Per Host
      • "n' Days summary - CPU %
      • "n' Days summary - Memory MB
      • "n' Days summary - Disk ms
      • Top 10 - CPU Usage
      • Top 10 - Memory Consumed
      • Top 10 - Disk (KBps)
      • Top 10 - Network (Mbps)

Any help on getting this additional functionality is highly appreciated.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Start with this

$report = @()
# $clusterName = "MyCluster"  $clusterName = "*"
$report = foreach($cluster in Get-Cluster -Name $clusterName){
    $esx = $cluster | Get-VMHost 
    $ds = Get-Datastore -VMHost $esx | where {$_.Type -eq "VMFS" -and $_.Extensiondata.Summary.MultipleHostAccess}

    New-Object PSObject -Property @{
        VCname = $cluster.Uid.Split(':@')[1]
        DCname = (Get-Datacenter -Cluster $cluster).Name
        Clustername = $cluster.Name
        "Number of hosts" = $esx.Count
        "Total Processors" = ($esx | measure -InputObject {$_.Extensiondata.Summary.Hardware.NumCpuPkgs} -Sum).Sum
        "Total Cores" = ($esx | measure -InputObject {$_.Extensiondata.Summary.Hardware.NumCpuCores} -Sum).Sum
        "Current CPU Failover Capacity" = $cluster.Extensiondata.Summary.AdmissionControlInfo.CurrentCpuFailoverResourcesPercent
        "Current Memory Failover Capacity" = $cluster.Extensiondata.Summary.AdmissionControlInfo.CurrentMemoryFailoverResourcesPercent
        "Configured Failover Capacity" = $cluster.Extensiondata.ConfigurationEx.DasConfig.FailoverLevel
        "Migration Automation Level" = $cluster.Extensiondata.ConfigurationEx.DrsConfig.DefaultVmBehavior
        "DRS Recommendations" = &{$result = $cluster.Extensiondata.Recommendation | %{$_.Reason};if($result){[string]::Join(',',$result)}}
        "DRS Faults" = &{$result = $cluster.Extensiondata.drsFault | %{$_.Reason};if($result){[string]::Join(',',$result)}}
        "Migration Threshold" = $cluster.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate
        "target hosts load standard deviation" = "NA"
       
"Current host load standard deviation" = "NA"                "Total Physical Memory (MB)" = ($esx | Measure-Object -Property MemoryTotalMB -Sum).Sum         "Configured Memory MB" = ($esx | Measure-Object -Property MemoryUsageMB -Sum).Sum         "Available Memroy (MB)" = ($esx | Measure-Object -InputObject {$_.MemoryTotalMB - $_.MemoryUsageMB} -Sum).Sum         "Total CPU (Mhz)" = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum         "Configured CPU (Mhz)" = ($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum         "Available CPU (Mhz)" = ($esx | Measure-Object -InputObject {$_.CpuTotalMhz - $_.CpuUsageMhz} -Sum).Sum         "Total Disk Space (MB)" = ($ds | where {$_.Type -eq "VMFS"} | Measure-Object -Property CapacityMB -Sum).Sum         "Configured Disk Space (MB)" = ($ds | Measure-Object -InputObject {$_.CapacityMB - $_.FreeSpaceMB} -Sum).Sum         "Available Disk Space (MB)" = ($ds | Measure-Object -Property FreeSpaceMB -Sum).Sum     } } $report | Export-Csv "C:\Cluster-Report.csv" -NoTypeInformation -UseCulture

It will produce most properties, except for the Performance tab entries.

I didn't understand what you wanted there, the values that are presented in these graphs ?

Also note that both standard deviation properties are marked as "NA".

The exact calculation method for those 2 hasn't been published afaik.


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

View solution in original post

20 Replies
LucD
Leadership
Leadership
Jump to solution

Start with this

$report = @()
# $clusterName = "MyCluster"  $clusterName = "*"
$report = foreach($cluster in Get-Cluster -Name $clusterName){
    $esx = $cluster | Get-VMHost 
    $ds = Get-Datastore -VMHost $esx | where {$_.Type -eq "VMFS" -and $_.Extensiondata.Summary.MultipleHostAccess}

    New-Object PSObject -Property @{
        VCname = $cluster.Uid.Split(':@')[1]
        DCname = (Get-Datacenter -Cluster $cluster).Name
        Clustername = $cluster.Name
        "Number of hosts" = $esx.Count
        "Total Processors" = ($esx | measure -InputObject {$_.Extensiondata.Summary.Hardware.NumCpuPkgs} -Sum).Sum
        "Total Cores" = ($esx | measure -InputObject {$_.Extensiondata.Summary.Hardware.NumCpuCores} -Sum).Sum
        "Current CPU Failover Capacity" = $cluster.Extensiondata.Summary.AdmissionControlInfo.CurrentCpuFailoverResourcesPercent
        "Current Memory Failover Capacity" = $cluster.Extensiondata.Summary.AdmissionControlInfo.CurrentMemoryFailoverResourcesPercent
        "Configured Failover Capacity" = $cluster.Extensiondata.ConfigurationEx.DasConfig.FailoverLevel
        "Migration Automation Level" = $cluster.Extensiondata.ConfigurationEx.DrsConfig.DefaultVmBehavior
        "DRS Recommendations" = &{$result = $cluster.Extensiondata.Recommendation | %{$_.Reason};if($result){[string]::Join(',',$result)}}
        "DRS Faults" = &{$result = $cluster.Extensiondata.drsFault | %{$_.Reason};if($result){[string]::Join(',',$result)}}
        "Migration Threshold" = $cluster.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate
        "target hosts load standard deviation" = "NA"
       
"Current host load standard deviation" = "NA"                "Total Physical Memory (MB)" = ($esx | Measure-Object -Property MemoryTotalMB -Sum).Sum         "Configured Memory MB" = ($esx | Measure-Object -Property MemoryUsageMB -Sum).Sum         "Available Memroy (MB)" = ($esx | Measure-Object -InputObject {$_.MemoryTotalMB - $_.MemoryUsageMB} -Sum).Sum         "Total CPU (Mhz)" = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum         "Configured CPU (Mhz)" = ($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum         "Available CPU (Mhz)" = ($esx | Measure-Object -InputObject {$_.CpuTotalMhz - $_.CpuUsageMhz} -Sum).Sum         "Total Disk Space (MB)" = ($ds | where {$_.Type -eq "VMFS"} | Measure-Object -Property CapacityMB -Sum).Sum         "Configured Disk Space (MB)" = ($ds | Measure-Object -InputObject {$_.CapacityMB - $_.FreeSpaceMB} -Sum).Sum         "Available Disk Space (MB)" = ($ds | Measure-Object -Property FreeSpaceMB -Sum).Sum     } } $report | Export-Csv "C:\Cluster-Report.csv" -NoTypeInformation -UseCulture

It will produce most properties, except for the Performance tab entries.

I didn't understand what you wanted there, the values that are presented in these graphs ?

Also note that both standard deviation properties are marked as "NA".

The exact calculation method for those 2 hasn't been published afaik.


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

pmeqix
Contributor
Contributor
Jump to solution

Hi Luc

That was really helpful. and yes for the performance I meant getting the chart numbers to represent them in a textual format in the report.

Also i got the following error's when running the script but it did complete successfully. so not sure what these errors mean and why they popped up?

Get-Datastore : Cannot validate argument on parameter 'VMHost'. The argument is
null or empty. Supply an argument that is not null or empty and then try the c
ommand again.
At C:\scripts\clusterstats.ps1:6 char:32
+     $ds = Get-Datastore -VMHost <<<<  $esx | where {$_.Type -eq "VMFS" -and $
_.Extensiondata.Summary.MultipleHostAccess}
    + CategoryInfo          : InvalidData: (:) [Get-Datastore], ParameterBindi
   ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
   ation.ViCore.Cmdlets.Commands.GetDatastore
Get-Datastore : Cannot validate argument on parameter 'VMHost'. The argument is
null or empty. Supply an argument that is not null or empty and then try the c
ommand again.
At C:\scripts\clusterstats.ps1:6 char:32
+     $ds = Get-Datastore -VMHost <<<<  $esx | where {$_.Type -eq "VMFS" -and $
_.Extensiondata.Summary.MultipleHostAccess}
    + CategoryInfo          : InvalidData: (:) [Get-Datastore], ParameterBindi
   ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
   ation.ViCore.Cmdlets.Commands.GetDatastore
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is strange, that would mean you have a cluster with no ESX(i) hosts in it somewhere ?


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

Reply
0 Kudos
pmeqix
Contributor
Contributor
Jump to solution

Luc

Yes currently we do not have any ESX(i) hosts in our environment. but that is changing by next week.

Any ideas on the performance tab info?

Reply
0 Kudos
coolvirtual
Contributor
Contributor
Jump to solution

Hi LucD

I need an HTML output for the cluster stastics script.


Can you help me with this?

thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Change the last line into

$report | ConvertTo-Html | Out-File .\report.html 

This will produce a very basic HTML page.

You can get very fancy, Alan's vCheck script is a very good example.


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

Reply
0 Kudos
coolvirtual
Contributor
Contributor
Jump to solution

My datasore is divided into 3 tiers..

Is there anyways I can get report on it serperately?

Reply
0 Kudos
FABSAN
Contributor
Contributor
Jump to solution

Why are these crossed out? Is there a way of getting this info via powercli? I've been trying to figure it out

Resource Allocation Tab

  • CPU
    • Total Capacity
    • Reserved Capacity
    • Available Capacity
  • Memory
    • Total Capacity
    • Reserved Capacity
    • Available Capacity
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The original author of the thread didn't seem to want these values.

But you retrieve them with PowerCLI, something like this

$cluster = Get-Cluster MyCluster 
$rp
= Get-View $cluster.ExtensionData.ResourcePool
Select -InputObject $cluster -Property Name,
@{N="CPU Total Capacity";E={$rp.Runtime.Cpu.MaxUsage}},
@{N="CPU Reserved Capacity";E={$rp.Runtime.Cpu.ReservationUsed}},
@{N="CPU Available Capacity";E={$rp.Runtime.Cpu.MaxUsage - $rp.Runtime.Cpu.ReservationUsed}},
@
{N="Memory Total Capacity";E={$rp.Runtime.Memory.MaxUsage}},
@{N="Memory Reserved Capacity";E={$rp.Runtime.Memory.ReservationUsed}},
@{N="Memory Available Capacity";E={$rp.Runtime.Memory.MaxUsage - $rp.Runtime.Memory.ReservationUsed}}

It shouldn't be too difficult to add these values to the report.


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

Reply
0 Kudos
FABSAN
Contributor
Contributor
Jump to solution

that worked, Thanks!

Reply
0 Kudos
FABSAN
Contributor
Contributor
Jump to solution

Hi LucD, I tried peicing together the two but getting errors. Seperately I was able to get it to work. I even went to a couple of book stores to find "VMware vSphere PowerCLI Reference" but it was unavailable. Any help putting together the two would be appreciated.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try it like this

$report = @()
$clusterName = "*"
$report = foreach($cluster in Get-Cluster -Name $clusterName){
    $esx = $cluster | Get-VMHost 
    $ds = Get-Datastore -VMHost $esx | where {$_.Type -eq "VMFS" -and $_.Extensiondata.Summary.MultipleHostAccess}
    $rp = Get-View $cluster.ExtensionData.ResourcePool
    New-Object PSObject -Property @{
        VCname = $cluster.Uid.Split(':@')[1]
        DCname = (Get-Datacenter -Cluster $cluster).Name
       
Clustername = $cluster.Name
       
"Number of hosts" = $esx.Count
       
"Total Processors" = ($esx | measure -InputObject {$_.Extensiondata.Summary.Hardware.NumCpuPkgs} -Sum).Sum
       
"Total Cores" = ($esx | measure -InputObject {$_.Extensiondata.Summary.Hardware.NumCpuCores} -Sum).Sum
       
"Current CPU Failover Capacity" = $cluster.Extensiondata.Summary.AdmissionControlInfo.CurrentCpuFailoverResourcesPercent
        "Current Memory Failover Capacity" = $cluster.Extensiondata.Summary.AdmissionControlInfo.CurrentMemoryFailoverResourcesPercent
       
"Configured Failover Capacity" = $cluster.Extensiondata.ConfigurationEx.DasConfig.FailoverLevel
        "Migration Automation Level" = $cluster.Extensiondata.ConfigurationEx.DrsConfig.DefaultVmBehavior
       
"DRS Recommendations" = &{$result = $cluster.Extensiondata.Recommendation | %{$_.Reason};if($result){[string]::Join(',',$result)}}         "DRS Faults" = &{$result = $cluster.Extensiondata.drsFault | %{$_.Reason};if($result){[string]::Join(',',$result)}}         "Migration Threshold" = $cluster.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate
       
"target hosts load standard deviation" = "NA"
       
"Current host load standard deviation" = "NA"                "Total Physical Memory (MB)" = ($esx | Measure-Object -Property MemoryTotalMB -Sum).Sum
       
"Configured Memory MB" = ($esx | Measure-Object -Property MemoryUsageMB -Sum).Sum
       
"Available Memroy (MB)" = ($esx | Measure-Object -InputObject {$_.MemoryTotalMB - $_.MemoryUsageMB} -Sum).Sum
       
"Total CPU (Mhz)" = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum
       
"Configured CPU (Mhz)" = ($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum
        "Available CPU (Mhz)" = ($esx | Measure-Object -InputObject {$_.CpuTotalMhz - $_.CpuUsageMhz} -Sum).Sum
       
"Total Disk Space (MB)" = ($ds | where {$_.Type -eq "VMFS"} | Measure-Object -Property CapacityMB -Sum).Sum
       
"Configured Disk Space (MB)" = ($ds | Measure-Object -InputObject {$_.CapacityMB - $_.FreeSpaceMB} -Sum).Sum
       
"Available Disk Space (MB)" = ($ds | Measure-Object -Property FreeSpaceMB -Sum).Sum
       
"CPU Total Capacity" = $rp.Runtime.Cpu.MaxUsage
       
"CPU Reserved Capacity" = $rp.Runtime.Cpu.ReservationUsed
       
"CPU Available Capacity" = $rp.Runtime.Cpu.MaxUsage - $rp.Runtime.Cpu.ReservationUsed
       
"Memory Total Capacity" = $rp.Runtime.Memory.MaxUsage
       
"Memory Reserved Capacity" = $rp.Runtime.Memory.ReservationUsed
       
"Memory Available Capacity" = $rp.Runtime.Memory.MaxUsage - $rp.Runtime.Memory.ReservationUsed
    } }
$report | Export-Csv "C:\Cluster-Report.csv" -NoTypeInformation -UseCulture


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

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Thanks for sharing the script, however I got this error message:

Get-Cluster : You have  modified the global:DefaultVIServer and global:DefaultVIServers system variables. This is not allowed. Please reset them to $null and reconnect to the vSphere server.
At C:\Users\Administrator\AppData\Local\Temp\37b5331b-c9c8-4190-b0af-d14ed3652fab.ps1:4 char:42
+ $report = foreach($cluster in Get-Cluster <<<<  -Name $clusterName){
    + CategoryInfo          : NotSpecified: (:) [Get-Cluster], InvalidState
    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidState,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster

what does that means ?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Does the following also return an error ?

Get-Cluster -Name *


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

FABSAN
Contributor
Contributor
Jump to solution

it worked, thanks again!

Reply
0 Kudos
DanTourangeau
Contributor
Contributor
Jump to solution

Great script LucD, really helpful!

I needed the DRS Faults part THANKS! 🙂

I was wondering if there any script to get the Storage DRS Faults?
I wasn't able to find anything on the web.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The only way I know of is to query the events with Get-VIEvent.

More specifically the DrsInvocationFailedEvent.
For example

$cluster = Get-Cluster -Name 'MyCluster'
Get-ViEvent -Entity $cluster -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-7) |
Where{$_ -is [VMware.Vim.DrsInvocationFailedEvent]}


You can check the DrsFault property on the Cluster object for the most recent faults.

$cluster = Get-Cluster -Name 'MyCluster'
$cluster.ExtensionData.DrsFault





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

Reply
0 Kudos
DanTourangeau
Contributor
Contributor
Jump to solution

Thanks LucD.

However, it show me only the Faults in the VMHost Clusters, I was looking to get the Faults in the Datastore Storage Cluster if that is possible? The script doesn't show me theses.

DanTourangeau_0-1702495784654.png

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since this whole thread is about clusters I assumed you also were talking about DRS faults, not SDRS faults.

But the concept is the same, there is also a DrsFault property in a DatastoreCluster.

$dsc = Get-DatastoreCluster -Name 'MyDSCluster'
$dsc.ExtensionData.PodStorageDrsEntry.DrsFault

 


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