1 2 Previous Next 23 Replies Latest reply on Mar 26, 2020 12:41 AM by LucD

    performance report

    dynobot Lurker

      I'm a newbie with powercli and my boss is asking me to generate an hourly report on cpu average, memory average, disk i/o, and network i/o.  Just picked up a book VMWare vSphere PowerCLI Reference but I'm overwhelmed with all the information.  Wondering if there is a similar script from anyone out there that I can use or tailor according to my need.

       

      Thanks

      Steve

        • 1. Re: performance report
          LucD Guru
          Community WarriorsvExpertUser Moderators

          Are these statistics to be on VMs or ESXi nodes?

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: performance report
            dynobot Lurker

            Of all the vms on my vCenter.

             

            Thanks

            Steve

            • 3. Re: performance report
              LucD Guru
              vExpertCommunity WarriorsUser Moderators

              Ok, let's start with a simple one.
              This will get the values for the past hour for all VMs, and then calculate the average over that hour for all 4 categories.

              Note that when you use the Get-Stat cmdlet without specifying any metrics on the Stat parameter, the cmdlet returns a number of metrics by default.

               

              We use the ErrorAction on the Get-Stat to avoid error messages for when there are not statistics available for that VM at the time speficied on the Start parameter.
              We call Get-Stat for all VMs in one call, then we use the Group-Object cmdlet to split up the results per VM.

              In the object returned by the Group-Object cmdlet we have the key (Name) on which we grouped, and all the values under a property named Group.

              On the objects present in Group, we now pull out the objects for specific metrics. Those we average.

              We do that in a calculated property on the Select (short for Select-Object) cmdlet.

               

              $vms = Get-VM

              $start = (Get-Date).AddHours(-1)

               

              Get-Stat -Entity $vms -Start $start -ErrorAction SilentlyContinue |

              Group-Object -Property {$_.Entity.Name} |

              Select @{N='VM';E={$_.Name}},

                  @{N='CPU(%)';E={"{0:N1}" -f ($_.Group | where{$_.MetricId -eq 'cpu.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

                  @{N='Memory(%)';E={"{0:N1}" -f ($_.Group | where{$_.MetricId -eq 'mem.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

                  @{N='Net(KBps)';E={"{0:N2}" -f ($_.Group | where{$_.MetricId -eq 'net.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

                  @{N='Disk(KBps';E={"{0:N2}" -f ($_.Group | where{$_.MetricId -eq 'disk.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}}

               

               

              The PowerCLI Reference is probably not the best book if you are just starting, it assumes a certain knowledge of PowerShell and a bit of PowerCLI.

              There are some quite good introductory books on PowerShell and PowerCLI.
              Have a look at these posts for pointers: PowerShell study guide – core concepts and the PowerCLI study guide – core concepts

               

              If you want learn a bit more on handling vSphere statistical data with PowerCLI, you could browse through the series of posts I did on PowerCLI and Statistics.
              It explains some of the core concepts, and then builds on that.

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: performance report
                dynobot Lurker

                Thank You Luc.  I ran the script and it came out something like below.  I'm just copying a few instead of all the VMs from the output.

                 

                VM    : V0AA0391_Linux
                CPU(%): 0.3

                Memory(%) : 0.9

                Net(KBps) : 0.00

                Disk(KBps : 0.21

                 

                VM    : V0AA0311_W2k8
                CPU(%): 4.1

                Memory(%) : 14.9

                Net(KBps) : 23.90

                Disk(KBps : 36.90

                 

                VM    : V0AA0255_Linux
                CPU(%): 2.8

                Memory(%) : 0.0

                Net(KBps) : 0.00

                Disk(KBps : 0.75

                 

                VM    : V0AA0290_Linux
                CPU(%): 1.0

                Memory(%) : 0.9

                Net(KBps) : 1.00

                Disk(KBps : 14.83

                 

                I'm now trying to export it to a file share.  Also, is there a way to have the output in a horizontal format?  It's probably easier to read.

                 

                Export-Csv '\\h0ac0001-file\IT\SYSTEMS GROUP\VMsPerf.csv' -NoTypeInformation -UseCulture

                 

                Thanks

                Steve

                • 5. Re: performance report
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  You can pipe the result to the Export-Csv cmdlet, like this.
                  The output will be one VM per row, and the values in different columns

                   

                   

                   

                  $vms = Get-VM

                  $start = (Get-Date).AddHours(-1)

                   

                  Get-Stat -Entity $vms -Start $start -ErrorAction SilentlyContinue |

                  Group-Object -Property {$_.Entity.Name} |

                  Select @{N='VM';E={$_.Name}},

                      @{N='CPU(%)';E={"{0:N1}" -f ($_.Group | where{$_.MetricId -eq 'cpu.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

                      @{N='Memory(%)';E={"{0:N1}" -f ($_.Group | where{$_.MetricId -eq 'mem.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

                      @{N='Net(KBps)';E={"{0:N2}" -f ($_.Group | where{$_.MetricId -eq 'net.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

                      @{N='Disk(KBps';E={"{0:N2}" -f ($_.Group | where{$_.MetricId -eq 'disk.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}} |

                  Export-Csv .\report.csv -NoTypeInformation -UseCulture

                   

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  1 person found this helpful
                  • 6. Re: performance report
                    dynobot Lurker

                    Thank you Luc.  The script ran like a charm and everything came out exactly how I wanted.  I will read up on your recommendations and hopefully, i can do more with it as far as adding more criteria and exporting it to html or graphical format for upper management.

                     

                    Thanks again.

                     

                    Steve

                    • 7. Re: performance report
                      pillror Lurker
                      Thank you so much for the nice script. I am looking for the script to find the DISK I/O and network IO for the past week. Shall I request you to see if you can provide here. Thank you so muc in advance.
                      • 8. Re: performance report
                        LucD Guru
                        Community WarriorsUser ModeratorsvExpert

                        Can you open a new thread for your request?

                        That makes it easier for other users to find the thread.

                        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        • 9. Re: performance report
                          yashcomp Lurker
                          I am very new to use powershell. When i am trying to run given script through powercli by logging in to vCenter IP, it is not showing result after 30 mins also at powercli screen and CSV file also doesn't have any output. How much time generally it takes.
                          • 10. Re: performance report
                            LucD Guru
                            Community WarriorsvExpertUser Moderators

                            Can you run simple PowerCLI cmdlets?

                            Something like

                             

                            Get-PowerCLIConfiguration

                            Connect-VIServer -Server <your-vCenter> -User <user> -Password <pswd>

                            Get-VMHost

                            Get-VM

                            Disconnect-VIServer -Confirm:$false

                             

                            Store those line in a file with the filetype .ps1

                            Then from the PowerShell prompt, enter the path to the .ps1 file (for example C:\Scripts\test.ps1)

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 11. Re: performance report
                              yashcomp Lurker

                              Hi LucD,

                              Thanks for your response. I was able to connect to VC and run the script given above to get performance report, but for VC it taking lot of time to response or I can say not getting output. Same script for VM performance report i have tried on Host where its working fine and giving proper output.

                              Is the script only designed for host or it is taking more time for VC as there are many VM's on that VC.

                              Thanks 

                              • 12. Re: performance report
                                LucD Guru
                                vExpertCommunity WarriorsUser Moderators

                                The script will work with a connection to any vSphere server, beit a vCenter or an ESXi node.
                                The longer runtime with a vCenter connection is most probably due to the higher number of VMs.
                                But it could also be due to the amount of data you pull from the vSphere server.

                                On an ESXi node, you will find only 1 hour of statistical data, on a vCenter, the data can go back to up to 1 year.

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                • 13. Re: performance report
                                  yashcomp Lurker

                                  Thanks LucD,

                                  Is there any other way to pull performance report or VM metrics of all the VM's under a VC.

                                  • 14. Re: performance report
                                    LucD Guru
                                    Community WarriorsUser ModeratorsvExpert

                                    Depends what you want to see in that report.

                                    If you are only interested in the current performance of the VM, you can fetch the values from the VirtualMachineQuickStats object.

                                    That's a (very) small subset of the metrics available with

                                     

                                    Get-Stat -Entity $vm -Stat $stat -Realtime -MaxSamples 1

                                     

                                    But for real performance statistics you'll have to use the Get-Stat cmdlet.
                                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                    1 2 Previous Next