1 2 3 Previous Next 30 Replies Latest reply on Feb 18, 2020 12:18 AM by ehsanijavad Go to original post
      • 15. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
        MrTaylor2 Novice

        Hi Luc

         

        That makes a bit more sense after reading your guide. I think I've got what I need with

         

        Add-PSSnapin VMware.VimAutomation.Core

        Connect-VIServer 'vcenter'

         

         

        $clusterName = 'cluster name'

         

        $stat = 'cpu.usagemhz.average','mem.usage.average'

        $entity = Get-Cluster -Name $clusterName

        $start = (Get-Date).AddDays(-30)

         

        Get-Stat -Entity $clusterName -Stat $stat -Start $start -MaxSamples 30 -IntervalMins 1440 |

        Group-Object -Property Timestamp |

        Sort-Object -Property Name |

        Select @{N='Cluster';E={$entity.Name}},

            @{N='Time';E={$_.Group[0].Timestamp}},

            @{N='CPU GHz Capacity';E={$script:capacity = [int]($entity.ExtensionData.Summary.TotalCPU/1000); $script:capacity}},

            @{N='CPU GHz Used';E={$script:used = [int](($_.Group | where{$_.MetricId -eq 'cpu.usagemhz.average'} | select -ExpandProperty Value)/1000); $script:used}},

            @{N='CPU % Free';E={[int](100 - $script:used/$script:capacity*100)}},

            @{N='Mem Capacity GB';E={$script:mcapacity = [int]($entity.ExtensionData.Summary.TotalMemory/1GB); $script:mcapacity}},

            @{N='Mem Used GB';E={$script:mused = [int](($_.Group | where{$_.MetricId -eq 'mem.usage.average'} | select -ExpandProperty Value) * $script:mcapacity/100); $script:mused}},

            @{N='Mem % Free';E={[int](100 - $script:mused/$script:mcapacity*100)}} |

        Export-Csv -Path C:\temp\cluster-stats.csv -notypeinformation

         

        Would you say that was the best way to do it until I can get the Export-Excel function to work?

        • 16. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          The Export-Excel function is quite easy to use.

          First, do you see the cmdlet?

          If you don't, you may have place the module in a wrong folder. Check your $PSModulePath variable.

          export-excel-1.jpg

          To use, you just pipe your objects to it.

          Something like this

           

          $clusterName = 'cluster name'

           

          $stat = 'cpu.usagemhz.average','mem.usage.average'

          $entity = Get-Cluster -Name $clusterName

          $start = (Get-Date).AddDays(-30)

           

          Get-Stat -Entity $clusterName -Stat $stat -Start $start -MaxSamples 30 -IntervalMins 1440 |

          Group-Object -Property Timestamp |

          Sort-Object -Property Name |

          Select @{N='Cluster';E={$entity.Name}},

              @{N='Time';E={$_.Group[0].Timestamp}},

              @{N='CPU GHz Capacity';E={$script:capacity = [int]($entity.ExtensionData.Summary.TotalCPU/1000); $script:capacity}},

              @{N='CPU GHz Used';E={$script:used = [int](($_.Group | where{$_.MetricId -eq 'cpu.usagemhz.average'} | select -ExpandProperty Value)/1000); $script:used}},

              @{N='CPU % Free';E={[int](100 - $script:used/$script:capacity*100)}},

              @{N='Mem Capacity GB';E={$script:mcapacity = [int]($entity.ExtensionData.Summary.TotalMemory/1GB); $script:mcapacity}},

              @{N='Mem Used GB';E={$script:mused = [int](($_.Group | where{$_.MetricId -eq 'mem.usage.average'} | select -ExpandProperty Value) * $script:mcapacity/100); $script:mused}},

              @{N='Mem % Free';E={[int](100 - $script:mused/$script:mcapacity*100)}} |

          Export-Excel -Path C:\Temp\cluster-stats.xlsx

           

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          1 person found this helpful
          • 17. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
            MrTaylor2 Novice

            HI Luc

             

            I figured out the problem. The function needs Powershell V3 at least and the server I was running it from was only V2. I've got it imported to my desktop now so hopefully it will work.

             

            Thanks a lot for all your help

            • 18. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
              MrTaylor2 Novice

              I've got a couple of questions Luc if you could spare me some more time.

               

              How would I be able to change the time of the collection. At the minute it has taken a counter for 01:00 every day. Is there a way to change this to sometime during the day or has it been aggregated already and that is just the display?

               

              Is there a way to do a Get-Cluster and the a foreach so that the script would only need to run against each vcenter server once? Ideally each cluster would appear on a separate worksheet

               

              Thanks

              • 19. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                Yes, that is the time the aggregation was done.

                 

                To run against all clusters, and store each cluster's data in a separate worksheet in the spreadsheet, you could do

                 

                $fileName = 'C:\Temp\cluster-stats.xlsx'

                $stat = 'cpu.usagemhz.average','mem.usage.average'

                $start = (Get-Date).AddDays(-30)

                 

                foreach($cluster in Get-Cluster){

                 

                    Get-Stat -Entity $cluster -Stat $stat -Start $start -MaxSamples 30 -IntervalMins 1440 |

                    Group-Object -Property Timestamp |

                    Sort-Object -Property Name |

                    Select @{N='Cluster';E={$cluster.Name}},

                        @{N='Time';E={$_.Group[0].Timestamp}},

                        @{N='CPU GHz Capacity';E={$script:capacity = [int]($cluster.ExtensionData.Summary.TotalCPU/1000); $script:capacity}},

                        @{N='CPU GHz Used';E={$script:used = [int](($_.Group | where{$_.MetricId -eq 'cpu.usagemhz.average'} | select -ExpandProperty Value)/1000); $script:used}},

                        @{N='CPU % Free';E={[int](100 - $script:used/$script:capacity*100)}},

                        @{N='Mem Capacity GB';E={$script:mcapacity = [int]($cluster.ExtensionData.Summary.TotalMemory/1GB); $script:mcapacity}},

                        @{N='Mem Used GB';E={$script:mused = [int](($_.Group | where{$_.MetricId -eq 'mem.usage.average'} | select -ExpandProperty Value) * $script:mcapacity/100); $script:mused}},

                        @{N='Mem % Free';E={[int](100 - $script:mused/$script:mcapacity*100)}} |

                    Export-Excel -Path $fileName -WorkSheetname $cluster.Name

                }

                 

                 

                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                • 20. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                  MrTaylor2 Novice

                  Something has gone a bit wrong. When running the original script I get

                   

                    

                  01/07/2016 01:0086415257641228
                  02/07/2016 01:0086336257641628
                  03/07/2016 01:0086326357641628
                  04/07/2016 01:008699057612379
                  05/07/2016 01:0086336257636337
                  06/07/2016 01:0086316457637235
                  07/07/2016 01:0086316457637435
                  08/07/2016 01:0086306557637934
                  09/07/2016 01:0086316457638334
                  10/07/2016 01:0086326357638433
                  11/07/2016 01:0086296657638533
                  12/07/2016 01:0086296657638633
                  13/07/2016 01:0086316457638433
                  14/07/2016 01:0086296657638533
                  15/07/2016 01:0086316457638633
                  16/07/2016 01:0086326357638733
                  17/07/2016 01:0086316457638932
                  18/07/2016 01:0086306557639032
                  21/06/2016 01:0086326357641428
                  22/06/2016 01:0086316457641528
                  23/06/2016 01:0086296657641528
                  24/06/2016 01:0086296657641528
                  25/06/2016 01:0086306557641628
                  26/06/2016 01:0086346057641628
                  27/06/2016 01:0086336257641628
                  28/06/2016 01:0086316457641628
                  29/06/2016 01:0086326357641628
                  30/06/2016 01:00863263576416

                  28

                   

                  With the new script it returns

                   

                       

                  01/07/2016 01:0086010057613177
                  02/07/2016 01:0086010057613177
                  03/07/2016 01:0086010057613177
                  04/07/2016 01:0086010057613177
                  05/07/2016 01:0086010057613177
                  06/07/2016 01:0086010057613177
                  07/07/2016 01:0086010057613177
                  08/07/2016 01:0086010057613177
                  09/07/2016 01:0086010057613177
                  10/07/2016 01:0086010057613177
                  11/07/2016 01:0086010057613177
                  12/07/2016 01:0086010057613177
                  13/07/2016 01:0086010057613177
                  14/07/2016 01:0086010057613177
                  15/07/2016 01:0086010057613177
                  16/07/2016 01:0086010057613177
                  17/07/2016 01:0086010057613177
                  18/07/2016 01:0086010057613177
                  19/07/2016 01:0086010057613177
                  22/06/2016 01:0086010057612578
                  23/06/2016 01:0086010057612578
                  24/06/2016 01:0086010057612578
                  25/06/2016 01:0086010057612578
                  26/06/2016 01:0086010057612578
                  27/06/2016 01:0086010057612578
                  28/06/2016 01:0086010057612578
                  29/06/2016 01:0086010057612578
                  30/06/2016 01:0086010057612578
                  • 21. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                    LucD Guru
                    Community WarriorsUser ModeratorsvExpert

                    Seems I forgot to replace some $entity by $cluster.

                    I updated the script above

                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                    • 22. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                      MrTaylor2 Novice

                      Brilliant.

                       

                      Thanks a lot for your help

                      • 23. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                        panhvr Enthusiast

                        Hello Luc,

                         

                        I do see performance chart in webclient but no results when I run below coomand

                         

                         

                        Webclient > clutserts > select cluster name > performance > advanced > CPU I do see values available from Feb

                         

                        PowerCLI C:\> Get-Cluster -Name Clustername | Get-Stat -start (get-date).AddDays(-40) -Finish (Get-Date).AddDays(-10) -MaxSamples 10000 -stat cpu.usage.average | Measure-Object -Property value -Average -Maximum -Minimum | select Average

                        PowerCLI C:\>

                        • 24. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                          panhvr Enthusiast

                          Hello LucD

                           

                          I opened a support case with VMware on this . They pointing the problem with latest version of PCLI interacion with vSpehre6.

                           

                          The same set of command works fine when I run against my other VC which is VCSA.

                          • 25. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                            ehsanijavad Novice

                            Hi, Thank you for your script. But I do not know why in last 30 Min result is wrong.

                            When I used -Realtime and -MaxSamples.

                             

                            Time               CPU GHz Capacity CPU GHz Used CPU % Free Mem Capacity GB Mem Used GB Mem % Free

                            ----                ---------------- ------------ ---------- --------------- ----------- ----------

                            14/02/2020 10:10:00              441          211         52            5342        4038         24

                            14/02/2020 10:15:00              441          216         51            5342        4037         24

                            14/02/2020 10:20:00              441          218         51            5342        4037         24

                            14/02/2020 10:25:00              441          209         53            5342        4037         24

                            14/02/2020 10:30:00              441          208         53            5342        4037         24

                            14/02/2020 10:35:00              441          213         52            5342        4037         24

                            14/02/2020 10:40:00              441          206         53            5342        4037         24

                            14/02/2020 10:45:00              441          197         55            5342        4037         24

                            14/02/2020 10:50:00              441          210         52            5342        4037         24

                            14/02/2020 10:55:00              441          203         54            5342        4037         24

                            14/02/2020 11:00:00              441          210         52            5342        4037         24

                            14/02/2020 11:05:00              441          240         46            5342        4037         24

                            14/02/2020 11:10:00              441          226         49            5342        4037         24

                            14/02/2020 11:15:00              441          222         50            5342        4037         24

                            14/02/2020 11:20:00              441          238         46            5342        4037         24

                            14/02/2020 11:25:00              441            0        100            5342        3575         33

                            14/02/2020 11:30:00              441            0        100            5342        2881         46

                            14/02/2020 11:35:00              441            0        100            5342        2881         46

                            14/02/2020 11:40:00              441            0        100            5342        2297         57

                            14/02/2020 11:45:00              441            0        100            5342        1283         76

                             

                            Thank you  for your answer.

                            • 26. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                              LucD Guru
                              User ModeratorsvExpertCommunity Warriors

                              Cluster performance data is created by one of the rollup processes running on the vCenter.

                              This rollup job runs every 30 minutes.

                              So for cluster data, the Realtime data is not really 'realtime', and you should not take the last 30 minutes into account.

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 27. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                                ehsanijavad Novice

                                Thank you so much for your answer.

                                • 28. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                                  ehsanijavad Novice

                                  This script works for some Cluster, but it does not work for some Cluster (in same datacenter).

                                   

                                  Get-Stat : 18/02/2020 08:32:02 Get-Stat This operation is restricted by the administrator - 'vpxd.stats.maxQueryMetrics'. Contact your

                                  system administrator.

                                  At line:7 char:16

                                  + $clusterName | Get-Stat -Stat $stat -MaxSamples 20  |

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

                                      + CategoryInfo          : NotSpecified: (:) [Get-Stat], RestrictedByAdministrator

                                      + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_GetStats_ErrorRetreivingPerfMetrics,VMware.VimAutomation.ViCore.Cmdlets.Com

                                     mands.GetViStats

                                   

                                  Thank you for your answer.

                                  • 29. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                                    LucD Guru
                                    vExpertCommunity WarriorsUser Moderators
                                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz