PowerCLI

 View Only
Expand all | Collapse all

ESXi Host Capacity Performance Report

  • 1.  ESXi Host Capacity Performance Report

    Posted Apr 13, 2015 01:08 PM

    Greetings all,

    I'm presently in the process of knocking up a PowerCLI script to report on all ESXi hosts across vCenters instances (x3).

    I came across the following group discussion on here which assisted immensely (see below link:)

    powercli script to capture cpu & mem usage stats

    I've since tweaked script ensuring just Hosts are to be reported:

    Connect-VIServer <server> -User <user> -Password <password>

    $allhosts = @()
    $hosts = Get-VMHost

    foreach($vmHost in $hosts){
      $hoststat = "" | Select HostName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
      $hoststat.HostName = $vmHost.name
     
      $statcpu = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-30) -Finish (Get-Date)-MaxSamples 10000 -stat cpu.usage.average
      $statmem = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-30) -Finish (Get-Date)-MaxSamples 10000 -stat mem.usage.average

      $cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
      $mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum
     
      $hoststat.CPUMax = $cpu.Maximum
      $hoststat.CPUAvg = $cpu.Average
      $hoststat.CPUMin = $cpu.Minimum
      $hoststat.MemMax = $mem.Maximum
      $hoststat.MemAvg = $mem.Average
      $hoststat.MemMin = $mem.Minimum
      $allhosts += $hoststat
    }
    $allhosts | Select HostName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin | Export-Csv "c:\Hosts.csv" -noTypeInformation

    In addition, both Network I/O and disk I/O (Datastore specific) would need to be captured too.

    Your ideas & assistance would be greatly appreciated.

    Thanks in advance.



  • 2.  RE: ESXi Host Capacity Performance Report

    Posted Apr 13, 2015 07:04 PM

    You can do something like this.

    But note that the disk statistics are the aggregate, in other words the average over all datastores.

    If you need this per datastore, you will need to use one or more of the datastore metrics (read and/or write).

    If you can have varying numbers of datastore on each host, how do you intend to present this ?

    Connect-VIServer <server> -User <user> -Password <password>

    $allhosts = @()

    $hosts = Get-VMHost

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

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

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

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

      $cpuStat = $_.Group | where{$_.MetricId -eq 'cpu.usage.average'} |

        Measure-Object -Property value -Average -Maximum -Minimum

      $memStat = $_.Group | where{$_.MetricId -eq 'mem.usage.average'} |

        Measure-Object -Property value -Average -Maximum -Minimum

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

        Measure-Object -Property value -Average -Maximum -Minimum

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

        Measure-Object -Property value -Average -Maximum -Minimum

           

      [pscustomobject]@{

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

        CPUAvg = $cpuStat.Average

        CPUMin = $cpuStat.Minimum

        CPUMax = $cpuStat.Maximum

        MemAvg = $cpuStat.Average

        MemMin = $cpuStat.Minimum

        MemMax = $cpuStat.Maximum

        NetAvg = $cpuStat.Average

        NetMin = $cpuStat.Minimum

        NetMax = $cpuStat.Maximum

        DiskAvg = $cpuStat.Average

        DiskMin = $cpuStat.Minimum

        DiskMax = $cpuStat.Maximum

      }

    }



  • 3.  RE: ESXi Host Capacity Performance Report

    Posted Apr 14, 2015 07:21 AM

    I really appreciate your prompt response LucD.

    I'm pretty much new to PowerCLI and relying heavily on feedback from the community on this.

    In answer to your question?  I guess what would be the easiest approach?  As of yet, there is no reporting mechanism in place on ESXi performance within team.  The following attributes need to be reported on:  active CPUs, CPU usage, Mem usage, Network I/O, Disk I/O.

    So let's assume disk is local to ESXi host?  How would this be reflected in final PowerCLI script?

    Any help would be greatly appreciated.



  • 4.  RE: ESXi Host Capacity Performance Report

    Posted Apr 14, 2015 08:54 AM

    Can you clarify what you want to see under "active CPUs" ?

    If I understand correctly there is only a local datastore connected to the ESXi, correct ?

    Which metric do you want to see for "Disk I/O" ?

    Have a look under the Performance tab in the client and determine which metric you are interested in, and then let me know



  • 5.  RE: ESXi Host Capacity Performance Report

    Posted Apr 14, 2015 11:45 AM

    I'm waiting on feedback from colleague.

    I'll reply as soon as I know.

    Many thanks for all your help.:smileyhappy:



  • 6.  RE: ESXi Host Capacity Performance Report

    Posted Apr 16, 2015 08:08 AM

    Hi LucD,

    Metrics for CPU counter, should remain as they are (e.g. average, min and max).

    Datastore metrics should be:

    Read latency

    Write latency

    Network metrics should be:

    Data transmit rate

    Data receive rate

    Usage

    Finalized script will be run against all vCenter instances within environment.

    In addition, my colleague has asked that raw informaton be extracted from the daily VC DB pertaining to ESXi Host CPU usage during the day!!  He has asked this due to above script only capuring the averages over the last (specified) time period and is concerned daily info may get lost.  I'm guessing, you'd suggest tweaking specified time period in script to capture this on a day to day basis, hence an additional script being run solely for ESXi Host usage?

    Any help would be kindly appreciated.



  • 7.  RE: ESXi Host Capacity Performance Report
    Best Answer

    Posted Apr 16, 2015 10:11 AM

    This should give you the request counters, but note that some of the metrics might require a specific Statistics level.

    My Stats Toolbox – A vSphere Server Performance Counter tool post provides a tool that will allow you to check that.

    Connect-VIServer <server> -User <user> -Password <password>

    $allhosts = @()

    $hosts = Get-VMHost

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

    $stat = 'cpu.usage.average','mem.usage.average','net.usage.average','net.bytesRx.average','net.bytesTx.average',

        'datastore.totalReadLatency.average','datastore.totalWriteLatency.average'

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

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

      $cpuStat = $_.Group | where{$_.MetricId -eq 'cpu.usage.average'} |

        Measure-Object -Property value -Average -Maximum -Minimum

      $memStat = $_.Group | where{$_.MetricId -eq 'mem.usage.average'} |

        Measure-Object -Property value -Average -Maximum -Minimum

          

      [pscustomobject]@{

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

        CPUAvg = $cpuStat.Average

        CPUMin = $cpuStat.Minimum

        CPUMax = $cpuStat.Maximum

        MemAvg = $cpuStat.Average

        MemMin = $cpuStat.Minimum

        MemMax = $cpuStat.Maximum

        NetUsage = $_.Group | where{$_.MetricId -eq 'net.usage.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average

        NetTr = $_.Group | where{$_.MetricId -eq 'net.bytesTx.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average

        NetRx = $_.Group | where{$_.MetricId -eq 'net.bytesRx.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average

        DSReadLatency = $_.Group | where{$_.MetricId -eq 'datastore.totalReadLatency.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average

        DSWriteLatency = $_.Group | where{$_.MetricId -eq 'datastore.totalWriteLatency.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average

      }

    }

    For your other question, that should indeed be another daily task.



  • 8.  RE: ESXi Host Capacity Performance Report

    Posted Apr 16, 2015 02:23 PM

    You're a life saver!! :smileyhappy:

    Many thanks for all your help and will refer to your Stats Toolbox.



  • 9.  RE: ESXi Host Capacity Performance Report

    Posted Apr 20, 2015 08:24 AM

    Hi LucD,

    Due to the enormity of our environment (datacenters, clusters, etc), I've decided to run script per vCenter instance as opposed to multiple instances all at once.

    I've noticed after perfoming a cut and paste of script (see attached), cursor just remains idle and blinks after the '-noTypeInformation.'

    Is this to be expected?

    This again occurred on Friday and I allowed script to run for a few hours and nothing happened!!

    Any assistance would be welcome?



  • 10.  RE: ESXi Host Capacity Performance Report

    Posted Apr 20, 2015 09:10 AM

    I would suggest you place the updated script in a .ps1 file, and then run that .ps1 file from the PowerCLI prompt (instead of pasting the script to the command prompt).

    Have a look at XtraVirt's Beginner's Guide.



  • 11.  RE: ESXi Host Capacity Performance Report

    Posted Apr 20, 2015 01:56 PM

    Many thanks.. :smileywink: