Home > Citrix, PowerShell Scripting, Scripting, Windows, Windows Server, XenApp > Monitoring Storage disk queue’s and IO with PowerShell

Monitoring Storage disk queue’s and IO with PowerShell

https://andymorgan.files.wordpress.com/2011/03/windows_powershell_icon.png?w=58&h=58&h=58Here’s one that used to bother me alot. The problem usually went as follows:

“Your XenApp servers have very high disk queue’s and IO”

“What’s causing it?”

“dunno…”

With Server 2008, the task manager’s resource monitor feature will help you find these items. But in server 2003 this was a perilous task. The specific details for disk io per process are stored in performance monitor under each specific process running. Trying to analyse each process was a massive pain, but powershell can do some very clever work to help alleviate this!

I wrote two quick functions which act similar to “top” in linux for giving an on screen view, updating at interval of what exactly is creating IO activity. These two functions are:

get-IODataBytes:

storageio

Get-IODataOperations

storageioops

The code for these functions are below:

function get-iodatabytes{
    $result=(get-counter -counter "\Process(*)\IO Data Bytes/sec" -ea 0).countersamples | ? {$_.cookedvalue -gt 0} | select instancename,@{Name="SessionID";Expression={if ($_.path.contains("#")){($_.path.split("#)"))[1]}else{"0"}}},@{Name="IO Data Bytes/sec";Expression={[math]::Round($_.cookedvalue,0)}},@{Name="IO Data KBytes/sec";Expression={[math]::Round($_.cookedvalue / 1024,0)}} | sort -Descending "IO Data Bytes/sec" | ft
    $currentqueue=(((get-counter -counter "\PhysicalDisk(0 C:)\Current Disk Queue Length" -ea 0).countersamples) | select cookedvalue).cookedvalue
    clear
    write-warning "Hit [CTRL] + [C] to exit live capture"
    write-host "Current Disk queue: $currentqueue"
    return $Result
}

FUnction get-IODataOperations {
    $result=(get-counter -counter "\Process(*)\IO Data Operations/sec" -ea 0).countersamples | ? {$_.cookedvalue -gt 0} | select instancename,@{Name="SessionID";Expression={if ($_.path.contains("#")){($_.path.split("#)"))[1]}else{"0"}}},@{Name="IO Data Operations/sec";Expression={[math]::Round($_.cookedvalue,0)}} | sort -Descending "IO Data Operations/sec" | ft
    $currentqueue=(((get-counter -counter "\PhysicalDisk(0 C:)\Current Disk Queue Length" -ea 0).countersamples) | select cookedvalue).cookedvalue
    clear
    write-warning "Hit [CTRL] + [C] to exit live capture"
    write-host "Current Disk queue: $currentqueue"
    return $Result
}

if you wish to loop one of these functions, simply use the following code:

while ($true){
get-iodataoperations
start-sleep 1
}
  1. J
    June 26, 2013 at 11:51 am

    Excellent, Will this work on Server 2012?

    • June 26, 2013 at 4:14 pm

      Should do!

      • J
        June 26, 2013 at 4:28 pm

        Thanks for the reply….

        Tired it and when running the PS script it doesn’t return any results nor any errors.

        Windows PowerShell
        Copyright (C) 2012 Microsoft Corporation. All rights reserved.

        PS C:\Windows\system32> cd\
        PS C:\> cd temp
        PS C:\temp> .\diskio.ps1
        PS C:\temp>

        function get-iodatabytes{
        $result=(get-counter -counter “\Process(*)\IO Data Bytes/sec” -ea 0).countersamples | ? {$_.cookedvalue -gt 0} | select instancename,@{Name=”SessionID”;Expression={if ($_.path.contains(“#”)){($_.path.split(“#)”))[1]}else{“0″}}},@{Name=”IO Data Bytes/sec”;Expression={[math]::Round($_.cookedvalue,0)}},@{Name=”IO Data KBytes/sec”;Expression={[math]::Round($_.cookedvalue / 1024,0)}} | sort -Descending “IO Data Bytes/sec” | ft
        $currentqueue=(((get-counter -counter “\PhysicalDisk(0 C:)\Current Disk Queue Length” -ea 0).countersamples) | select cookedvalue).cookedvalue
        clear
        write-warning “Hit [CTRL] + [C] to exit live capture”
        write-host “Current Disk queue: $currentqueue”
        return $Result
        }

        FUnction get-IODataOperations {
        $result=(get-counter -counter “\Process(*)\IO Data Operations/sec” -ea 0).countersamples | ? {$_.cookedvalue -gt 0} | select instancename,@{Name=”SessionID”;Expression={if ($_.path.contains(“#”)){($_.path.split(“#)”))[1]}else{“0″}}},@{Name=”IO Data Operations/sec”;Expression={[math]::Round($_.cookedvalue,0)}} | sort -Descending “IO Data Operations/sec” | ft
        $currentqueue=(((get-counter -counter “\PhysicalDisk(0 C:)\Current Disk Queue Length” -ea 0).countersamples) | select cookedvalue).cookedvalue
        clear
        write-warning “Hit [CTRL] + [C] to exit live capture”
        write-host “Current Disk queue: $currentqueue”
        return $Result
        }

  1. No trackbacks yet.

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

%d bloggers like this: