PowerCLI

 View Only
Expand all | Collapse all

performance report

  • 1.  performance report

    Posted Oct 05, 2017 05:14 PM

    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



  • 2.  RE: performance report

    Posted Oct 05, 2017 05:20 PM

    Are these statistics to be on VMs or ESXi nodes?



  • 3.  RE: performance report

    Posted Oct 05, 2017 05:23 PM

    Of all the vms on my vCenter.

    Thanks

    Steve



  • 4.  RE: performance report

    Posted Oct 05, 2017 05:39 PM

    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.



  • 5.  RE: performance report

    Posted Oct 05, 2017 08:03 PM

    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



  • 6.  RE: performance report
    Best Answer

    Posted Oct 05, 2017 08:16 PM

    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

     



  • 7.  RE: performance report

    Posted Oct 05, 2017 11:43 PM

    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



  • 8.  RE: performance report

    Posted Jan 26, 2018 04:01 PM
    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.


  • 9.  RE: performance report

    Posted Jan 26, 2018 04:44 PM

    Can you open a new thread for your request?

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



  • 10.  RE: performance report

    Posted Feb 10, 2020 12:01 PM

    Hi LucD,

    I'm very new to powercli, how to get Host performance graphical report... is it possible ?



  • 11.  RE: performance report

    Posted Feb 10, 2020 12:10 PM

    What kind of graphical report do you have in mind?



  • 12.  RE: performance report

    Posted Feb 11, 2020 03:03 AM

    Thanks for response, I'm looking for host and individual current CPU,datastore &memory consumption report...



  • 13.  RE: performance report

    Posted Feb 11, 2020 07:38 AM

    That's not what I mean.

    Are for example graphs that can be produced in Excel an option?



  • 14.  RE: performance report

    Posted Feb 11, 2020 07:49 AM

    Sorry bro...7 days old details



  • 15.  RE: performance report

    Posted Feb 11, 2020 08:06 AM

    Actually  we need a report for capacity planning like what is the current capacity and how is the CPU and memory utilization  for the past one month? Memory here is consumed memory and also CPU its better if we can calculate vcpus remaining  rather than ghz.



  • 16.  RE: performance report

    Posted Feb 11, 2020 08:28 AM


  • 17.  RE: performance report

    Posted Mar 26, 2020 01:08 AM

    Can this be done on specific list of VMs? Also, will this be straight thru PowerCLI? How can I make it to run automatically every 2-hours? Can this be run thru Windows scheduler?

    Thank you in advance.



  • 18.  RE: performance report

    Posted Mar 26, 2020 07:42 AM

    Yes, you can do this in many ways.

    Through a mask in the Name field.

    $vms = Get-VM -Name vm*

    From a file

    $vms = Get-VM -Name (Import-Csv -Path .\vmnames.csv -UseCulture).vmnames


    For your other questions, I suggest to do a search in this community or create a new thread.



  • 19.  RE: performance report

    Posted May 31, 2020 01:14 PM

    LucD,

    When i try with specific vm's name it throws an error.

    Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null o

    At D:\nilay\VM_Perform_report.ps1:1 char:20

    + ... Get-VM -Name(Import-Csv -Path C:\temp\vmnames.csv -UseCulture).vmname ...

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

        + CategoryInfo          : InvalidData: (:) [Get-VM], ParameterBindingValidationException

        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

    Get-Stat : 5/31/2020 8:11:22 AM Get-Stat                Value cannot be found for the mandatory parameter Entity

    At D:\nilay\VM_Perform_report.ps1:6 char:1

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

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

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

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

    Any help is appreciated.

    Thanks

    V



  • 20.  RE: performance report

    Posted May 31, 2020 02:30 PM

    Do you actually have a column VMName in that CSV?



  • 21.  RE: performance report

    Posted Aug 23, 2018 11:11 AM
    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.


  • 22.  RE: performance report

    Posted Aug 23, 2018 11:17 AM

    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)



  • 23.  RE: performance report

    Posted Aug 24, 2018 06:00 AM

    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 



  • 24.  RE: performance report

    Posted Aug 24, 2018 06:08 AM

    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.



  • 25.  RE: performance report

    Posted Aug 24, 2018 07:53 AM

    Thanks LucD,

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



  • 26.  RE: performance report

    Posted Aug 24, 2018 08:52 AM

    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.


  • 27.  RE: performance report

    Posted May 31, 2020 12:45 PM

    LucD,

    Can we get the report for a specific set of VM's or list of VM's ? E.g. C:\temp\servers.txt

    Thanks

    V