1 2 3 Previous Next 30 Replies Latest reply on Feb 18, 2020 12:18 AM by ehsanijavad

    Powercli Script to Capture ESXi Cluster CPU & Memory Usage

    MrTaylor2 Novice

      Hello All,

       

      I'm having the hardest time creating a script that will give me Cluster CPU and Memory Usage. I just need something simple if there is such a thing?

       

      Example of what I'm looking for:

       

      Cluster nameCPU GHz CapacityCPU GHz UsedCPU % Free

       

      Cluster nameMemory CapacityMemory UsedMemory % Free

       

       

      I need to present these in graphical format but I could look to do something with a pivot table afterwards.

       

      Any help would be greatly appreciated.


      Thanks

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

          The following will get the data into an Excel spreadheet.

          It uses the Export-Excel cmdlet from the Doug's ImportExcel module.

          You can change the Start date.

          The script places everything in one worksheet, but it can easily be adapted to have separate worksheets for CPU and memory.

           

           

          $clusterName = 'MyCluster'

           

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

          $entity = Get-Cluster -Name $clusterName

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

           

          Get-Stat -Entity $clusterName -Stat $stat -Start $start |

          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:\cluster-stats.xlsx -WorkSheetname 'Stats' -AutoSize -FreezeTopRow

           

           

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

            Thanks for the very quick reply LucD!

             

            I've got Doug's ImportExcel module downloaded but I'm having issues getting it imported. We are using PowerCli 5.8. This is my error

             

            Unable to find type [PSPlot]: make sure that the assembly containing this type is loaded.

            At C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ImportExcel\ImportExcel.psm1:25 char:29

            +         [OutputType([PSPlot] <<<< )]

                + CategoryInfo          : InvalidOperation: (PSPlot:String) [], ParentContainsErrorRecordException

                + FullyQualifiedErrorId : TypeNotFound

             

             

            Import-Module : The specified module '.\ImportExcel.psm1' was not loaded because no valid module file was found in any module directory.

            At line:1 char:14

            + Import-Module <<<<  .\ImportExcel.psm1

                + CategoryInfo          : ResourceUnavailable: (.\ImportExcel.psm1:String) [Import-Module], FileNotFoundException

                + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

             

            I checked the .psd1 and there wasn't a  minimum version specified

             

            Instead of specifying the Cluster would it be possible to return all clusters in each vCenter server? or would that require a loop?

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

              After a bit of research it looks like it doesn't like Get-Stat -Entity "Cluster"

               

              If I replace the cluster name with the name of my vcenter server the command runs successfully.

               

              Get-Stat -Entity 'vcenter' -Stat $stat -Start $start

               

              works without any issues

               

              This is the error

               

              Get-Stat : 13/07/2016 15:24:58    Get-Stat        A specified parameter was not correct.

              querySpec.size   

              At line:13 char:9

              + Get-Stat <<<<  -Entity $clusterName -Stat $stat -Start $start |

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

                  + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_GetStats_ErrorRetreivingPerfMetrics,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

              • 4. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                LucD Guru
                vExpertUser ModeratorsCommunity Warriors

                Are you by any chance on vSPhere 5.5U3 ?

                Then it might be the problem described in Veeam's KB2071

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

                  Hello LucD

                   

                  Get-Stat -Entity clustername is resulting nothing after upgrade of vSpehre 6 U2 even after setting adavance setting to -1

                   

                  Get-AdvancedSetting -Entity YourvCenter -Name config.vpxd.stats.MaxQueryMetrics |

                  Set-AdvancedSetting -Value -1

                  • 6. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                    LucD Guru
                    Community WarriorsUser ModeratorsvExpert

                    Did you check the value of maxQuerySize in the file vpxd.cfg ?

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

                      Hello LucD,

                       

                      Thanks for your reply.

                       

                      Below is entry in vpxd.cfg file

                       

                      <stats>

                            <maxQueryMetrics>-1</maxQueryMetrics>

                          </stats>

                          <support>

                      • 8. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                        LucD Guru
                        vExpertUser ModeratorsCommunity Warriors

                        Depending on which Historical Interval you are looking at, you will have to wait till the aggregation jobs have done their thing.

                        What interval are you looking at?

                        When did you change the value?

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

                          Before upgrading the VC I was able to collect up to 90 days of CPU and memory usage at cluster entity . Now I dont see results for even 2 days ..

                          I have changed the advance settings a day before

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

                            And do you see that Performance data in the vSphere or Web client?

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

                              We are on vSphere 5.5U3. Unfortunately we won't be able to apply their workaround as that applies to the Veeam One application

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

                                That is indeed a Veeam KB article, but has no further relation to a Veeam product.

                                It's purely a vCenter issue.

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

                                  Yep. It helped when I clicked through to the vmware kb rather than just reading that page.

                                   

                                  I'm followed that in our lab and it seems to have done the trick although I'll have to revisit the Export-Excel function.

                                   

                                  The output has displayed in 30 minute intervals. Is there a way to total these in the script as if I run this for the 30 day interval requested there will be a lot of data generated.

                                   

                                  I really appreciate your help

                                  • 14. Re: Powercli Script to Capture ESXi Cluster CPU & Memory Usage
                                    LucD Guru
                                    vExpertCommunity WarriorsUser Moderators

                                    If you run for a 30 day interval you will get 1 observation per day.

                                    See my PowerCLI & vSphere statistics – Part 1 – The basics for some info on Historical Intervals.

                                     

                                    But if want to have an average per day/per week/per month, that can be done.

                                    Let me know what you would to have.

                                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                    1 2 3 Previous Next