PowerCLI

 View Only
Expand all | Collapse all

Get-Stat -Disk Response

  • 1.  Get-Stat -Disk Response

    Posted Dec 04, 2013 01:00 PM

    Hi,

    I have been reviewing the various threads for a discussion on the output from the Get-Stat '-disk' element as am trying to understand the IOPS of a VM. When running the below command I am returned 'disk.usage.average' where the 'Description' states that this is the average Disk I/O rate, however the 'Unit' field states that the measurement is in KBps.

    I would have expected the unit field to be IOPS as this in itself is a unit of measurement? Or am I getting this wrong?

    Command: Get-Stat -Entity SERVERx -Realtime -disk -MaxSamples 1 | Export-Csv ServerX.csv

    Output:

    Thanks all in advance.

    Danny



  • 2.  RE: Get-Stat -Disk Response

    Posted Dec 04, 2013 01:13 PM

    For IOPS have a look at my Get the maximum IOPS post.

    In there I show how you calculate the IOPS rate



  • 3.  RE: Get-Stat -Disk Response

    Posted Dec 04, 2013 01:29 PM

    Will take a look - thanks for the prompt response.

    Danny



  • 4.  RE: Get-Stat -Disk Response

    Posted Dec 10, 2013 11:29 AM

    Hi LucD / All,

    Thanks for this, the link was a great help - I've continued working with this and I can export all of the information however it takes the attached format (Names down the first column and values down the second) where I want the values from left to right with as I iterate down through the various VM's.

    How it looks:

    How I want it to look:

    Code

    _____________________________________________________________________________________________________________

    $format = "-Property Entity, TimeStamp, IntervalSecs, ReadValue, WriteValue"

    $Read = "disk.numberread.summation"

    $Write = "disk.numberwrite.summation"

    $IntervalSecs = 20

    $MaxSamples = 1

    $arrVM = Get-VM  | where-object {$_.PowerState -eq "PoweredOn"}

    $arrVM = Get-VM  | where-object {$_.Name -eq "ServerA"}

    foreach ($objVM in  $arrVM)

    {

       

        $VMReadValue = Get-Stat -Entity $objVM -Realtime -Stat $Read -MaxSamples $MaxSamples -IntervalSecs $IntervalSecs

        $VMWriteValue = Get-Stat -Entity $objVM -Realtime -Stat $Write -MaxSamples $MaxSamples -IntervalSecs $IntervalSecs

        

        $rEntity = $VMReadValue.Entity.Name

        $rMetricId = $VMReadValue.MetricId

        $rTimestamp = $VMReadValue.Timestamp

        $IntervalSecs = $VMReadValue.IntervalSecs

        $rUnit = $VMReadValue.Unit

        $rValue = $VMReadValue.Value

        $wValue = $VMWriteValue.Value

       

        $VMStats =@{"Entity" = $rEntity; "TimeStamp" = $rTimestamp; "IntervalSecs" = $IntervalSecs; "ReadValue" = $rValue; "WriteValue" = $wValue}

       

        $VMStats.getEnumerator() | Select Name, Value | Export-Csv VMstat.csv

        $VMStats

       

    }



  • 5.  RE: Get-Stat -Disk Response

    Posted Dec 10, 2013 11:53 AM

    Managed to do it with a conversion function... very useful :smileyhappy:

    function ConvertTo-Object($hashtable)

    {

       $object = New-Object PSObject

       $hashtable.GetEnumerator() |

          ForEach-Object { Add-Member -inputObject $object `

        -memberType NoteProperty -name $_.Name -value $_.Value }

       $object | Export-Csv VMstat.csv

    }

    #$hash = @{Entity=$rEntity; TimeStamp=$rTimestamp; IntervalSecs=$IntervalSecs; ReadValue=$rValue; WriteValue=$wValue}

    #$hash

    #ConvertTo-Object $hash

    ################################

    $format = "-Property Entity, TimeStamp, IntervalSecs, ReadValue, WriteValue"

    $Read = "disk.numberread.summation"

    $Write = "disk.numberwrite.summation"

    #$IntervalSecs = 20

    #$MaxSamples = 1

    #$arrVM = Get-VM  | where-object {$_.PowerState -eq "PoweredOn"}

    $arrVM = Get-VM  | where-object {$_.Name -eq "ServerA"}

    foreach ($objVM in  $arrVM)

    {

       

        $VMReadValue = Get-Stat -Entity $objVM -Realtime -Stat $Read -MaxSamples 1 -IntervalSecs 20

        $VMWriteValue = Get-Stat -Entity $objVM -Realtime -Stat $Write -MaxSamples 1 -IntervalSecs 20

        

        $rEntity = $VMReadValue.Entity.Name

        $rMetricId = $VMReadValue.MetricId

        $rTimestamp = $VMReadValue.Timestamp

        $IntervalSecs = $VMReadValue.IntervalSecs

        $rUnit = $VMReadValue.Unit

        $rValue = $VMReadValue.Value

        $wValue = $VMWriteValue.Value

       

        $VMStats =@{"Entity" = $rEntity; "TimeStamp" = $rTimestamp; "IntervalSecs" = $IntervalSecs; "ReadValue" = $rValue; "WriteValue" = $wValue}

       

        #$VMStats.getEnumerator() | Select Name, Value | Export-Csv VMstat.csv

        $VMStats

        ConvertTo-Object $VMStats

       

    }



  • 6.  RE: Get-Stat -Disk Response

    Posted Dec 10, 2013 01:18 PM

    This is an alternative, without the extra function.

    $format = "-Property Entity, TimeStamp, IntervalSecs, ReadValue, WriteValue"
    $Read = "disk.numberread.summation"
    $Write = "disk.numberwrite.summation"
    $IntervalSecs = 20
    $MaxSamples = 1
    $arrVM = Get-VM  | where-object {$_.PowerState -eq "PoweredOn"}
    $arrVM = Get-VM  | where-object {$_.Name -eq "ServerA"}

    $report = @()
    foreach ($objVM in  $arrVM)
    {
       
    $VMReadValue = Get-Stat -Entity $objVM -Realtime -Stat $Read -MaxSamples $MaxSamples -IntervalSecs $IntervalSecs
       
    $VMWriteValue = Get-Stat -Entity $objVM -Realtime -Stat $Write -MaxSamples $MaxSamples -IntervalSecs $IntervalSecs

           
    $row = "" | Select Entity,MetricID,TimeStamp,IntervalSecs,Unit,ReadValue,WriteValue
       
    $row.Entity = $VMReadValue.Entity.Name
       
    $row.MetricId = $VMReadValue.MetricId
       
    $row.Timestamp = $VMReadValue.Timestamp
       
    $$row.IntervalSecs = $VMReadValue.IntervalSecs
       
    $row.Unit = $VMReadValue.Unit
       
    $row.ReadValue = $VMReadValue.Value
       
    $row.WriteValue = $VMWriteValue.Value

       
    $report += $row
    }
    $report | Export-Csv VMstat.csv -NoTypeInformation -UseCulture


  • 7.  RE: Get-Stat -Disk Response

    Posted Dec 10, 2013 03:56 PM

    Thanks for this LucD - a much cleaner way of doing this. I have added in some calculations to yours out the IOPS also and its populating nicely.

    Is there any reason the -Append won't work as I would rather keep this all within a single spreadsheet.

    Thanks,


    Danny



  • 8.  RE: Get-Stat -Disk Response

    Posted Dec 10, 2013 06:49 PM

    The Append switch should work, provided the rows in the CSV file have the same layout as the records you want to append.

    Did you get an error message ?



  • 9.  RE: Get-Stat -Disk Response

    Posted Dec 11, 2013 08:56 AM

    I just added it to the Export-CSV statment:

    _________________________________________________________________

        $report += $row

    }

    $report | Export-Csv VMstat.csv -NoTypeInformation -UseCulture -Append

    _________________________________________________________________

    Error:

    [vSphere PowerCLI] C:\Users\daniel.major\Storage\PowerShell> .\LucDStat.ps1

    Export-Csv : A parameter cannot be found that matches parameter name 'Append'.

    At C:\Users\daniel.major\Storage\PowerShell\LucDStat.ps1:28 char:71

    + $report | Export-Csv VMstat.csv -NoTypeInformation -UseCulture -Append <<<<

        + CategoryInfo          : InvalidArgument: (:) [Export-Csv], ParameterBindingException

        + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand



  • 10.  RE: Get-Stat -Disk Response

    Posted Dec 11, 2013 09:07 AM

    It looks like you might be running an older PowerShell version.

    Do a

    $PSVersionTable

    at the prompt.

    If that variable doesn't exist, you're most probably running PowerShell v1.

    Check with

    $host.Version

    The Append switch on the Export-Csv cmdlet was added in PowerShell v2.



  • 11.  RE: Get-Stat -Disk Response

    Posted Dec 11, 2013 09:20 AM

    That was my initial thought as well - I checked teh versiona dn its definately V2.0 I assume the append switch worked on your system?

    [vSphere PowerCLI] C:\Users\daniel.major\Storage\PowerShell> $PSVersionTable

    Name                           Value

    ----                           -----

    CLRVersion                     2.0.50727.5472

    BuildVersion                   6.1.7601.17514

    PSVersion                      2.0

    WSManStackVersion              2.0

    PSCompatibleVersions           {1.0, 2.0}

    SerializationVersion           1.1.0.1

    PSRemotingProtocolVersion      2.1

    [vSphere PowerCLI] C:\Users\daniel.major\Storage\PowerShell> $host.Version

    Major  Minor  Build  Revision

    -----  -----  -----  --------

    2      0      -1     -1

    [vSphere PowerCLI] C:\Users\daniel.major\Storage\PowerShell>



  • 12.  RE: Get-Stat -Disk Response
    Best Answer

    Posted Dec 11, 2013 09:32 AM

    My mistake, the Append switch was introduced in PowerShell v3, not v2



  • 13.  RE: Get-Stat -Disk Response

    Posted Dec 11, 2013 09:37 AM

    ah - that makes sense. Off to the Change Control Team then for an upgrade...

    Thanks a lot for the assistance - very much appreciated.

    Danny