PowerCLI

 View Only
Expand all | Collapse all

How to capture CPU, Mem , Disk , Network performance

  • 1.  How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 10:16 AM

    Dear Team,

    I want to capture CPU, Mem , Disk & Network performance and need to save the same in .CSV file . Need ur assistance on the same.

    regards

    Mr Vmware



  • 2.  RE: How to capture CPU, Mem , Disk , Network performance

    Broadcom Employee
    Posted Sep 11, 2014 10:23 AM

    Better you explore RVTools (:RVTools - Home one of comprehensive tools) or ESXTOP (ESXTOP - Yellow Bricks)



  • 3.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 10:28 AM

    Thanks Vicky.

    But I want powercli script t o capture all 4 food groups.

    regards

    Mr VMware



  • 4.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 10:48 AM

    Do you need these counters for VMs or ESXi ?

    And do you want these counters per default interval, or grouped per hour/per day... ?

    Any specific counters you want to see ?



  • 5.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 11:23 AM


    Thanks LUCD for prmpt resposne.

    Hey LUCD I want these for VMs and also for ESXi host

    I want to run this script after every 3 hour

    then after two three days our required will be for per day.

    need ur urgent asisstance



  • 6.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 12:22 PM

    Try something like this

    It uses 4 general counters, and it will produce a CSV for the VMs and a CSV for the ESXi hosts for the last 3 hours.

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

    $stat = "cpu.usage.average","mem.usage.average","disk.usage.average","net.usage.average"

    $vms = Get-VM

    &{Get-Stat -Entity $vms -Start $start -Stat $stat |

    Group-Object -Property Timestamp,EntityId | %{

        New-Object PSObject -Property @{

            Time = $_.Group[0].Timestamp

            VM = $_.Group[0].Entity.Name

            CPU = $_.Group | where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} | Select -ExpandProperty Value

            Mem = $_.Group | where {$_.MetricId -eq "mem.usage.average" -and $_.Instance -eq ""} | Select -ExpandProperty Value

            Disk = $_.Group | where {$_.MetricId -eq "disk.usage.average" -and $_.Instance -eq ""} | Select -ExpandProperty Value

            Net = $_.Group | where {$_.MetricId -eq "net.usage.average" -and $_.Instance -eq ""} | Select -ExpandProperty Value

        }

    }} | Select Time,VM,CPU,Mem,Disk,Net | Export-Csv vm-report.csv -NoTypeInformation -UseCulture

    $esx = Get-VMHost

    &{Get-Stat -Entity $esx -Start $start -Stat $stat |

    Group-Object -Property Timestamp,EntityId | %{

        New-Object PSObject -Property @{

            Time = $_.Group[0].Timestamp

            VM = $_.Group[0].Entity.Name

            CPU = $_.Group | where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} | Select -ExpandProperty Value

            Mem = $_.Group | where {$_.MetricId -eq "mem.usage.average" -and $_.Instance -eq ""} | Select -ExpandProperty Value

            Disk = $_.Group | where {$_.MetricId -eq "disk.usage.average" -and $_.Instance -eq ""} | Select -ExpandProperty Value

            Net = $_.Group | where {$_.MetricId -eq "net.usage.average" -and $_.Instance -eq ""} | Select -ExpandProperty Value

        }

    }} | Select Time,VM,CPU,Mem,Disk,Net | Export-Csv esx-report.csv -NoTypeInformation -UseCulture



  • 7.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 12:32 PM

    Once  logged in on host through PCLI then how to run this script.

    Sorry I m new in scripting no idea how to proceed.

    Need ur assistance.

    regards

    Mr VMware



  • 8.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 12:56 PM

    Have a look at the XtraVirt introduction on using PowerCLI here.



  • 9.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 02:28 PM

    Thanks very helful.

    Ihave coxpied ur script in notepad and connect one of the esxi server and tried to run that script but getting below error

    PowerCLI C:\temp> .\vm.ps1 > test.txt
    Get-Stat : 9/11/2014 7:53:26 PM    Get-Stat        The metric counter "cpu.usag
    e.average" doesn't exist for entity "Windows Test VM - old".
    At C:\temp\vm.ps1:9 char:11
    + &{Get-Stat <<<<  -Entity $vms -Start $start -Stat $stat |
        + CategoryInfo          : ResourceUnavailable: (cpu.usage.average:String)
       [Get-Stat], VimException
        + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics
       _MetricDoesntExist,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

    Get-Stat : 9/11/2014 7:53:26 PM    Get-Stat        The metric counter "mem.usag
    e.average" doesn't exist for entity "Windows Test VM - old".
    At C:\temp\vm.ps1:9 char:11
    + &{Get-Stat <<<<  -Entity $vms -Start $start -Stat $stat |
        + CategoryInfo          : ResourceUnavailable: (mem.usage.average:String)
       [Get-Stat], VimException
        + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics
       _MetricDoesntExist,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

    Get-Stat : 9/11/2014 7:53:26 PM    Get-Stat        The metric counter "disk.usa
    ge.average" doesn't exist for entity "Windows Test VM - old".
    At C:\temp\vm.ps1:9 char:11
    + &{Get-Stat <<<<  -Entity $vms -Start $start -Stat $stat |
        + CategoryInfo          : ResourceUnavailable: (disk.usage.average:String)
        [Get-Stat], VimException
        + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics
       _MetricDoesntExist,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

    Get-Stat : 9/11/2014 7:53:26 PM    Get-Stat        The metric counter "net.usag
    e.average" doesn't exist for entity "Windows Test VM - old".
    At C:\temp\vm.ps1:9 char:11
    + &{Get-Stat <<<<  -Entity $vms -Start $start -Stat $stat |
        + CategoryInfo          : ResourceUnavailable: (net.usage.average:String)
       [Get-Stat], VimException
        + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics
       _MetricDoesntExist,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

    Unable to find type [ordered]: make sure that the assembly containing this type
    is loaded.
    At C:\temp\vm.ps1:13 char:14
    +     [ordered] <<<< @{
        + CategoryInfo          : InvalidOperation: (ordered:String) [], RuntimeEx
       ception
        + FullyQualifiedErrorId : TypeNotFound

    Unable to find type [ordered]: make sure that the assembly containing this type
    is loaded.
    At C:\temp\vm.ps1:13 char:14
    +     [ordered] <<<< @{
        + CategoryInfo          : InvalidOperation: (ordered:String) [], RuntimeEx
       ception
        + FullyQualifiedErrorId : TypeNotFound

    Unable to find type [ordered]: make sure that the assembly containing this type
    is loaded.
    At C:\temp\vm.ps1:13 char:14
    +     [ordered] <<<< @{
        + CategoryInfo          : InvalidOperation: (ordered:String) [], RuntimeEx
       ception
        + FullyQualifiedErrorId : TypeNotFound

    Unable to find type [ordered]: make sure that the assembly containing this type
    is loaded.
    At C:\temp\vm.ps1:13 char:14
    +     [ordered] <<<< @{
        + CategoryInfo          : InvalidOperation: (ordered:String) [], RuntimeEx
       ception
        + FullyQualifiedErrorId : TypeNotFound

    Unable to find type [ordered]: make sure that the assembly containing this type
    is loaded.
    At C:\temp\vm.ps1:13 char:14
    +     [ordered] <<<< @{
        + CategoryInfo          : InvalidOperation: (ordered:String) [], RuntimeEx
       ception
        + FullyQualifiedErrorId : TypeNotFound

    Unable to find type [ordered]: make sure that the assembly containing this type
    is loaded.
    At C:\temp\vm.ps1:13 char:14
    +     [ordered] <<<< @{
        + CategoryInfo          : InvalidOperation: (ordered:String) [], RuntimeEx
       ception
        + FullyQualifiedErrorId : TypeNotFound



  • 10.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 11, 2014 03:24 PM

    It seems that some of the VMs do not have statistical data available.

    You can ignore those by using the ErrorAction parameter on the Get-Stat cmdlet.

    Get-Stat -Entity $esx -Start $start -Stat $stat -ErrorAction SlientlyContinue


    Which PowerShell version are you using ?

    The [ordered] cast was introduced in PowerShell v3.

    Do a $psversiontable to see which version you are running.



  • 11.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 16, 2014 08:36 AM

    Previosuly I wans running this script with Win2K8 now im able to run this run script from 2012 R2 server.


    I m not getting proper output PFA file..

    Need ur assistance on the same.



  • 12.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 16, 2014 11:05 AM

    I changed the script above, have another try



  • 13.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 16, 2014 11:56 AM

    thanks LUCD it's giving me output after 20 sec interval....

    PFA report I want report after every 3 hour or 1 day.



  • 14.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Sep 16, 2014 06:07 PM

    Try like this.

    It will average the values over 3 hours, and that for the last day.

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

    $stat = "cpu.usage.average","mem.usage.average","disk.usage.average","net.usage.average"

    $vms = Get-VM

    &{Get-Stat -Entity $vms -Start $start -Stat $stat |

    Group-Object -Property EntityId,{[math]::Floor($_.Timestamp.Hour/3)} | %{

        New-Object PSObject -Property @{

            Time = $_.Group[0].Timestamp

            VM = $_.Group[0].Entity.Name

            CPU = $_.Group | where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} |

                Measure-Object -Property Value -Average | Select -ExpandProperty Average

            Mem = $_.Group | where {$_.MetricId -eq "mem.usage.average" -and $_.Instance -eq ""} |

                Measure-Object -Property Value -Average | Select -ExpandProperty Average

            Disk = $_.Group | where {$_.MetricId -eq "disk.usage.average" -and $_.Instance -eq ""} |

                Measure-Object -Property Value -Average | Select -ExpandProperty Average

            Net = $_.Group | where {$_.MetricId -eq "net.usage.average" -and $_.Instance -eq ""} |

                Measure-Object -Property Value -Average | Select -ExpandProperty Average

        }

    }} | Select Time,VM,CPU,Mem,Disk,Net | Export-Csv vm-report.csv -NoTypeInformation -UseCulture

    The VMHost script can be done in a similar way.



  • 15.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Jan 19, 2015 12:27 AM

    I'm having exact problem in loading the ordered list as below:

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

    So does installing the Powershell 4.0 Windows6.1-KB2819745-x64-MultiPkg.msu can resolve this problem ?



  • 16.  RE: How to capture CPU, Mem , Disk , Network performance

    Posted Jan 19, 2015 05:49 AM

    Yes, you need at least PS v3 to have the [ordered] cast available.