Skip to content

Instantly share code, notes, and snippets.

@mastry
Last active June 15, 2019 17:02
Show Gist options
  • Save mastry/0d712c0114369c4e6a0928052edd475d to your computer and use it in GitHub Desktop.
Save mastry/0d712c0114369c4e6a0928052edd475d to your computer and use it in GitHub Desktop.
Continuously sample the queue depth of a single queue on multiple servers. Handy for troubleshooting.
param(
[string[]]
$ComputerName,
[string]
$QueueName,
[int]
$SampleRate = 5 # once every 5 seconds
)
while ($true) {
Write-Host "Collecting sample..."
$SampleTime = [System.DateTime]::Now
$Results = $ComputerName | ForEach-Object {
gwmi -Class Win32_PerfRawData_MSMQ_MSMQQueue -ComputerName $_ -Filter "Name='$_\\private$\\$($QueueName)'"
}
$Results | ForEach-Object { Write-Output "$($SampleTime),$($_.PSComputerName),$($_.MessagesInQueue)" }
$Summary = $Results | Measure-Object MessagesInQueue -Average -Minimum -Maximum
Write-Host "Avg: $($Summary.Average), Min: $($Summary.Minimum), Max: $($Summary.Maximum)"
Write-Host "Waiting for next sample period....Press ctrl+c to exit"
Start-Sleep -Seconds $SampleRate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment