Get-Stat2 : another way of getting at the statistical data

Version 1

    With the release of PowerCLI v4 the Get-Stat cmdlet has been much improved.

     

    In October 2008, as a temporary solution for the problems with the Get-Stat cmdlet in older PowerCLI or VITK releases, I wrote the Get-Stat2 script.

    The Get-Stat2 script allows lightly different parameters than the regular Get-Stat cmdlet.

     

    For that reason I will make the Get-Stat2 script available again (the original document was removed some time ago).

     

    But please only use this script when you couldn't get the result you needed with the current Get-Stat cmdlet!

     

    An extract from the original document:

    The script accepts the following parameters:

    -Entity <VIObject>     : the object for which the statiscal data will be collected. Only 1 object allowed !
    -Start <DateTime>     : start of the interval
    -Finish <DateTime>     : end of the interval
    -Stat <string[]>     : array of statistic identifiers
    -Instance <string>     : some statistic identifiers allow instances.
                            ("" : aggregate (default) / "*" : all instances / array of specific instances)
    -Interval <string>     : desired sampling interval, allowed values: "RT","HI1","HI2","HI3","HI4"
                     RT : real time
                              HI : historical interval
                             (results in these defaults 20, 300, 1800, 7200, 86400 seconds)
    -Maxsamples <int32>     : only for "Real time" interval; number of intervals
    -QueryMetrics          : return all available metrics for the Entity
    -QueryInstances     : return all available instances for the Entity and Stat
    

     

    Update 01/11/08

    When you add a new resource to an entity, the statistical data for historical intervals will not be available immediately.

    You will have to wait at least till the sampling period of the historical interval has expired.

    The QueryPerf method will return sampling periods (date/time stamps) but there will be no statistical data (yet).

     

    Example:

    • you add a vCPU to a virtual machine

    • data for HI2 for that CPU instance will only be available after +/- 30 minutes

     

    The minimum wait time to see data for a new resource:

    • RT     20 secs

    • HI1    5 mins

    • HI2    30 mins

    • HI3    2 hours

    • HI4    1 day

     

    To avoid errors from the Get-Stat2 function a test was added to verify if any data was returned by the QueryPerf method.

    If there is no data, the Get-Stat2 function returns $null.

     

    The attached script has been updated.

     

    Update 15/02/09

    The attached Get-Stat2.ps1 script has been updated.

    The changes:

    • corrected MaxSamples parameter

    • corrected Cluster entity clastype

    • corrected missing Start and Finish parameters test

    • added -QueryMetrics option

    • added -QueryInstances option

     

    With the addition of these last two parameters, the script can now be used to

    • query all the valid metrics for a specific entity

    • query all the valid instances for one or more metrics

     

    Example -QueryMetrics

    
    $esx = Get-VMHost <ESX-hostname> | Get-View
    ./Get-Stat2.ps1 -entity $esx -querymetrics |ft
    
    

     

     

    produces an array of custom objects like this

    
    Group                Name                               Rollup                  Id               Level                Type Unit
    -----                ----                               ------                  --               -----                ---- ----
    clusterServices      cpufairness                        latest                 105                   1            absolute number
    clusterServices      memfairness                        latest                 106                   1            absolute number
    cpu                  idle                            summation                 112                   3               delta millisecond
    cpu                  reservedCapacity                  average                 110                   2            absolute megaHertz
    cpu                  usage                             average                   2                   1                rate percent
    cpu                  usage                             maximum                   4                   4                rate percent
    cpu                  usage                             minimum                   3                   4                rate percent
    cpu                  usagemhz                          average                   6                   1                rate megaHertz
    cpu                  usagemhz                          maximum                   8                   4                rate megaHertz
    cpu                  usagemhz                          minimum                   7                   4                rate megaHertz
    cpu                  used                            summation                 111                   3               delta millisecond
    disk                 busResets                       summation                 115                   3               delta number
    disk                 commands                        summation                 113                   3               delta number
    disk                 commandsAborted                 summation                 114                   3               delta number
    disk                 deviceLatency                     average                 156                   2            absolute millisecond
    disk                 deviceReadLatency                 average                 148                   2            absolute millisecond
    disk                 deviceWriteLatency                average                 152                   2            absolute millisecond
    disk                 kernelLatency                     average                 157                   2            absolute millisecond
    disk                 kernelReadLatency                 average                 149                   2            absolute millisecond
    disk                 kernelWriteLatency                average                 153                   2            absolute millisecond
    disk                 numberRead                      summation                  91                   3               delta number
    disk                 numberWrite                     summation                  92                   3               delta number
    disk                 queueLatency                      average                 159                   2            absolute millisecond
    disk                 queueReadLatency                  average                 151                   2            absolute millisecond
    ...
    
    

     

     

    Example QueryInstances

     

     

    
    $esx = Get-VMHost <ESX-hostname> | Get-View
    ./Get-Stat2-v1.1.ps1 -entity $esx -stat "disk.deviceLatency.average","net.received.average" -queryinstances | ft
    
    

     

     

    produces an array of custom objects like this

    
    Stat                                                                    Instance
    ----                                                                    --------
    disk.deviceLatency.average                                              vmhba0:0:0
    disk.deviceLatency.average                                              vmhba0:1:0
    disk.deviceLatency.average                                              vmhba32:0:0
    disk.deviceLatency.average                                              vmhba32:0:1
    disk.deviceLatency.average                                              vmhba32:1:0
    disk.deviceLatency.average                                              vmhba32:11:0
    disk.deviceLatency.average                                              vmhba32:2:0
    disk.deviceLatency.average                                              vmhba32:2:1
    disk.deviceLatency.average                                              vmhba32:6:0
    disk.deviceLatency.average                                              vmhba32:6:1
    disk.deviceLatency.average                                              vmhba32:7:0
    disk.deviceLatency.average                                              vmhba32:7:1
    disk.deviceLatency.average                                              vmhba32:8:0
    net.received.average                                                    vmnic0
    net.received.average                                                    vmnic1
    net.received.average                                                    vmnic2
    net.received.average                                                    vmnic3
    
    

     

     

    Note that an instance can have a length zero for some metrics.

    This ("") is the instance that returns the aggregated statistics value.

    
    $esx = Get-VMHost <ESX-hostname> | Get-View
    ./Get-Stat2-v1.1.ps1 -entity $esx -stat "cpu.usage.average" -queryinstances | ft
    
    

     

     

    returns

    
    Stat                                                                    Instance
    ----                                                                    --------
    cpu.usage.average
    cpu.usage.average                                                       0
    cpu.usage.average                                                       1
    
    

     

     

    The first object in the array is the "aggregate" instance.

     

    Update 02/03/09

    The attached Get-Stat2.ps1 script has been updated.

    The changes:

    • corrected issue with missing -Maxsamples parameter

    • corrected issue with incorrect instances returned for -QueryInstances

    • introduced default value ("RT") for -Interval parameter