Storage Spaces Tiering – SSD Hit Ratio Custom Perfmon counter

Following on my previous script to track the tiering optimization job, I wanted to have better realtime statistics on how much the SSD tier is getting used. I came up with the following solution that integrates nicely in the regular perfmon tool and could be sent to OpsMgr if required. A word of warning (and a question to the community), only the SSD read hit ratio works at this point in time. It looks like when I update both the read and write counters, the counters get incorrect value for some reason. Maybe someone has a pro tip on that issue!

You first need to setup the counters on the server using the following script:

Setup-SSDHitRatioPerfCounters

$categoryName = "Storage Spaces Tier - Custom"

$categoryHelp = "Custom performance counters for Storage Spaces Tiering"
$categoryType = [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance

$categoryExists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName)


If ($categoryExists)
{
    [System.Diagnostics.PerformanceCounterCategory]::Delete($categoryName)    
}
$objCCDC = New-Object System.Diagnostics.CounterCreationDataCollection
  
$objCCD1 = New-Object System.Diagnostics.CounterCreationData
$objCCD1.CounterName = "Read Hit Ratio"
$objCCD1.CounterType = [System.Diagnostics.PerformanceCounterType]::NumberOfItems32
$objCCD1.CounterHelp = "SSD Hit Ratio"
$objCCDC.Add($objCCD1) | Out-Null

$objCCD2 = New-Object System.Diagnostics.CounterCreationData
$objCCD2.CounterName = "Write Hit Ratio"
$objCCD2.CounterType = [System.Diagnostics.PerformanceCounterType]::NumberOfItems32
$objCCD2.CounterHelp = "SSD Hit Ratio"
$objCCDC.Add($objCCD2) | Out-Null

[System.Diagnostics.PerformanceCounterCategory]::Create($categoryName, $categoryHelp, $categoryType, $objCCDC) | Out-Null

Once that’s done, you can run the following script that will sample the read/write perfmon counters every 15 seconds and update the hit ratio custom performance counter.

Get-SSDTierHitRatio

$volumes=Get-Volume | Where {$_.FileSystemLabel -like "*POOL*"}

$servers=$env:COMPUTERNAME

while($true)
{
    $ssdRatios=@()

    foreach($volume in $volumes)
    {
        
        foreach($server in $servers)
        {
            $volumeCounters=(get-counter -ComputerName $server -ListSet "Storage Spaces Tier").PathsWithInstances | where {$_ -like "*"+$volume.FileSystemLabel + "*Tier * Bytes/sec"}

            if($volumeCounters -ne $null)
            {
                $value=Get-Counter -Counter $volumeCounters -ComputerName $server

                $hddReadBytes=$value.CounterSamples | where {$_.Path -like "*hddtier*" -and $_.Path -like "*read*"}
                $ssdReadBytes=$value.CounterSamples | where {$_.Path -like "*ssdtier*" -and $_.Path -like "*read*"}
                $hddWriteBytes=$value.CounterSamples | where {$_.Path -like "*hddtier*" -and $_.Path -like "*write*"}
                $ssdWriteBytes=$value.CounterSamples | where {$_.Path -like "*ssdtier*" -and $_.Path -like "*write*"}

                $totalBytesRead=$ssdReadBytes.CookedValue+$hddReadBytes.CookedValue
                $totalBytesWritten=$ssdWriteBytes.CookedValue+$hddWriteBytes.CookedValue
                if($totalBytesRead -gt 0)
                {
                    $ssdReadRatio=$ssdReadBytes.CookedValue/$totalBytesRead
                }
                else
                {
                    $ssdReadRatio=0
                }

                if($totalBytesWritten -gt 0)
                {
                    $ssdWriteRatio=$ssdWriteBytes.CookedValue/$totalBytesWritten
                }
                else
                {
                    $ssdWriteRatio=0
                }


                $ssdRatio=New-Object PSObject -Property @{Volume=$volume.FileSystemLabel;
                                                                SSDReadRatio=$ssdReadRatio;
                                                                SSDWriteRatio=$ssdWriteRatio;
                                                                SampleTime=Get-Date;
                                                                Server=$server
                                                              }
                $readPerformanceInstance=New-Object System.Diagnostics.PerformanceCounter("Storage Spaces Tier - Custom", "Read Hit Ratio", $volume.FileSystemLabel, $false)
                #$writePerformanceInstance=New-Object System.Diagnostics.PerformanceCounter("Storage Spaces Tier - Custom", "Write Hit Ratio", $volume.FileSystemLabel, $false)
                
                $readPerformanceInstance.RawValue=$ssdRatio.SSDReadRatio*100
                
                #$writePerformanceInstance.RawValue=$ssdRatio.SSDWriteRatio*100
                

                $ssdRatios+=$ssdRatio
 
            }
        }

    }
    $ssdRatios | Select SampleTime,Volume,Server,SSDReadRatio,SSDWriteRatio | ft
    $ssdRatios | Select SampleTime,Volume,Server,SSDReadRatio,SSDWriteRatio | Export-Csv -Path \\etfsinc.com\share\apps\GEMAutomation\StorageSpaces\TierHitRatios.csv -NoTypeInformation -Append
    Write-Host "Waiting for next sample"
    Start-Sleep -Seconds 15
}

If you have any questions about this, let me know!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s