12 Replies Latest reply on Nov 14, 2019 7:59 AM by markshannon

    Maximum, Minimum and Average CPU & Memory usage per cluster

    NucleusVM Novice

      Hi,

       

      I need to get Maximum, Minimum and Average CPU & Memory usage per cluster. For a specific amount of time. for example a week. Currently I am using this:

       

      foreach($vmHost in Get-VMHost){
        $hoststat = "" | Select HostName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
        $hoststat.HostName = $vmHost.name

        $statcpu = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-7) -Finish (Get-Date)-MaxSamples 100 -stat cpu.usage.average
        $statmem = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-7) -Finish (Get-Date)-MaxSamples 100 -stat mem.usage.average

        $cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
        $mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum

        $hoststat.CPUMax = $cpu.Maximum
        $hoststat.CPUAvg = $cpu.Average
        $hoststat.CPUMin = $cpu.Minimum
        $hoststat.MemMax = $mem.Maximum
        $hoststat.MemAvg = $mem.Average
        $hoststat.MemMin = $mem.Minimum
        $allhosts += $hoststat
      }
      $allhosts | Select HostName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin | Export-Csv $outputfile -noTypeInformation

       

      This though gives me the information I want, per host, not per cluster.

      How can I get this information per cluster?

      Thanks

        • 1. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          For the Historical Intervals you can use a cluster on the Entity parameter.

          Like this

           

          $allClusters = @()

           

          Get-Cluster | %{

           

              $clusstat = "" | Select ClusterName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin

              $clusstat.ClusterName = $_.Name

           

              $statcpu = Get-Stat -Entity $_ -Start (get-date).AddDays(-7) -Finish (Get-Date)-MaxSamples 100 -Stat cpu.usage.average

              $statmem = Get-Stat -Entity $_ -Start (get-date).AddDays(-7) -Finish (Get-Date)-MaxSamples 100 -Stat mem.usage.average

           

              $cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum

              $mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum

           

              $clusstat.CPUMax = $cpu.Maximum

              $clusstat.CPUAvg = $cpu.Average

              $clusstat.CPUMin = $cpu.Minimum

              $clusstat.MemMax = $mem.Maximum

              $clusstat.MemAvg = $mem.Average

              $clusstat.MemMin = $mem.Minimum

              $allClusters += $hoststat

          }

           

          $allClusters |

          Select ClusterName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin |

          Export-Csv $outputfile -noTypeInformation

           

          • 2. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
            NucleusVM Novice

            Thanks for the info. I have a couple of problems.

             

            I get message in ISE saying "Get-Stat, A specific parameter was not correct, querySpec.size"

             

            and the spread sheet shows identical information for all the clusters, and no cluster name. (see screen shot)

            • 3. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

              You seem to be hitting the issue documented in KB2107096

              • 4. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                markshannon Novice

                Hi,

                just responding as per reply from you on Re:Solved: get cluster utilization info as this may be better as i only want a cluster average etc rthe than on hosts.

                 

                the KB2107096 i do not appear to have config.vpxd.stats.MaxQueryMetrics?

                 

                running 6.7

                 

                thanks

                mark

                • 5. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  Then you might need to add it (provided you are seeing that error).

                   

                  Get-Cluster |

                  New-AdvancedSetting -Name config.vpxd.stats.maxQueryMetrics -Value -1 -Confirm:$false

                  • 6. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                    markshannon Novice

                    i just get the below:-

                     

                    PS C:\temp> Get-Cluster | New-AdvancedSetting -Name config.vpxd.stats.maxQueryMetrics -Value -1 -Confirm:$true

                    New-AdvancedSetting : 13/11/2019 13:56:35 New-AdvancedSetting 'Type' parameter is mandatory for Cluster

                    entities.

                    At line:1 char:15

                    + ... t-Cluster | New-AdvancedSetting -Name config.vpxd.stats.maxQueryMetri ...

                    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                        + CategoryInfo          : InvalidArgument: (:) [New-AdvancedSetting], ViError

                        + FullyQualifiedErrorId : Core_NewAdvancedSetting_TryValidateTypeParameter_TypeNotSpecifiedForCluster,VM

                       ware.VimAutomation.ViCore.Cmdlets.Commands.NewAdvancedSetting

                    • 7. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                      LucD Guru
                      User ModeratorsCommunity WarriorsvExpert

                      Yes, that needs the Type parameter

                       

                      Get-Cluster |

                      New-AdvancedSetting -Name config.vpxd.stats.maxQueryMetrics -Value -1 -Type VIServer -Confirm:$false

                      • 8. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                        markshannon Novice

                        no luck?

                         

                        New-AdvancedSetting : 13/11/2019 14:33:32 New-AdvancedSetting Settings of type 'VIServer' are not valid for

                        entity of type 'ClusterImpl'.

                        At line:2 char:1

                        + New-AdvancedSetting -Name config.vpxd.stats.maxQueryMetrics -Value -1 ...

                        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                            + CategoryInfo          : InvalidArgument: (HEX-IT:ClusterImpl) [New-AdvancedSetting], ViError

                            + FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_NewAdvancedSetting_InvalidSettingType,VMw

                           are.VimAutomation.ViCore.Cmdlets.Commands.NewAdvancedSetting

                        • 9. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                          LucD Guru
                          Community WarriorsUser ModeratorsvExpert

                          I'm obviously not yet fully awake
                          That setting goes on the VCSA

                           

                          New-AdvancedSetting -Entity $global:DefaultVIServer -Name config.vpxd.stats.maxQueryMetrics -Value -1 -Type VIServer -Confirm:$false

                          1 person found this helpful
                          • 10. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                            markshannon Novice

                            haha i know that feeling

                             

                            Perfect that worked this time without error.

                             

                            I've shortened this script as only want average and not too fussed about min/max etc but nothing appears in $allclusters yet one of the clusters with averages appears in $clusstat, $statcpu etc.... i know what im missing but dont know how to add the collected details to $allclusters?  sorry for being a pain...

                             

                            $allClusters = @()

                             

                            Get-Cluster | %{

                                $clusstat = "" | Select ClusterName, MemAvg, CPUAvg

                                $clusstat.ClusterName = $_.Name

                                $statcpu = Get-Stat -Entity $_ -Start (get-date).AddDays(-7) -Finish (Get-Date) -Stat cpu.usage.average

                                $statmem = Get-Stat -Entity $_ -Start (get-date).AddDays(-7) -Finish (Get-Date) -Stat mem.usage.average

                                $cpu = $statcpu | Measure-Object -Property value -Average

                                $mem = $statmem | Measure-Object -Property value -Average

                                $clusstat.CPUAvg = $cpu.Average

                                $clusstat.MemAvg = $mem.Average

                             

                            }

                            • 11. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                              LucD Guru
                              User ModeratorsvExpertCommunity Warriors

                              Try like this

                               

                              $allClusters = @()

                              Get-Cluster | %{

                                  $clusstat = "" | Select ClusterName, MemAvg, CPUAvg

                                  $clusstat.ClusterName = $_.Name

                                  $statcpu = Get-Stat -Entity $_ -Start (get-date).AddDays(-7) -Finish (Get-Date) -Stat cpu.usage.average

                                  $statmem = Get-Stat -Entity $_ -Start (get-date).AddDays(-7) -Finish (Get-Date) -Stat mem.usage.average

                                  $cpu = $statcpu | Measure-Object -Property value -Average

                                  $mem = $statmem | Measure-Object -Property value -Average

                                  $clusstat.CPUAvg = $cpu.Average

                                  $clusstat.MemAvg = $mem.Average

                                  $allClusters += $clusstat

                              }


                              $allClusters

                              1 person found this helpful
                              • 12. Re: Maximum, Minimum and Average CPU & Memory usage per cluster
                                markshannon Novice

                                Brilliant - worked a treat - ThankYou

                                I've also managed to add your logic in for 'business hours/working days' for a month as below

                                 

                                $workingDays = "Monday","Tuesday","Wednesday","Thursday","Friday"

                                $dayStart = New-Object DateTime(1,1,1,7,30,0)     # 07:30 AM

                                $dayEnd = New-Object DateTime(1,1,1,17,30,0)      # 05:30 PM

                                 

                                $allClusters = @()

                                Get-Cluster | %{

                                    $clusstat = "" | Select ClusterName, CPUAvg, MemAvg

                                    $clusstat.ClusterName = $_.Name

                                    #$statcpu = Get-Stat -Entity $_ -Start $todayMidnight.AddDays(-14) -Finish $todayMidnight.AddDays(-7) -Stat cpu.usage.average | Where-Object {$workingDays -contains $_.Timestamp.DayOfWeek -and $_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and $_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay}

                                    #$statmem = Get-Stat -Entity $_ -Start $todayMidnight.AddDays(-14) -Finish $todayMidnight.AddDays(-7) -Stat mem.usage.average | Where-Object {$workingDays -contains $_.Timestamp.DayOfWeek -and $_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and $_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay}

                                    $statcpu = Get-Stat -Entity $_ -Start (get-date).AddDays(-30) -Finish (Get-Date) -Stat cpu.usage.average | Where-Object {$workingDays -contains $_.Timestamp.DayOfWeek -and $_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and $_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay}

                                    $statmem = Get-Stat -Entity $_ -Start (get-date).AddDays(-30) -Finish (Get-Date) -Stat mem.usage.average | Where-Object {$workingDays -contains $_.Timestamp.DayOfWeek -and $_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and $_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay}

                                    $cpu = $statcpu | Measure-Object -Property value -Average

                                    $mem = $statmem | Measure-Object -Property value -Average

                                    $clusstat.CPUAvg = $cpu.Average

                                    $clusstat.MemAvg = $mem.Average

                                    $allClusters += $clusstat

                                }

                                 

                                $allClusters | select ClusterName, @{n="CPUAvg"; e={[Math]::ceiling($_.CPUavg)}}, @{n="MemAvg"; e={[Math]::ceiling($_.Memavg)}}