How to monitor Application Request Routing via PowerShell
Dear readers,
Welcome back. Today I want to discuss with you how to monitor Application Request Routing via PowerShell script. In case that you are wondering what ARR is, probably you have to give a look at following link: https://www.iis.net/downloads/microsoft/application-request-routing
Of course ARR has some tools and performance counters available to monitor its status, like:
Anyway, there are scenarios where it is required a script to monitor how ARR server and application servers work. In a scenario like this, you could use PowerShell. The following example shows an example of script.
#####################################################################################
# THIS IS SAMPLE CODE AND IS ENTIRELY UNSUPPORTED. THIS CODE AND INFORMATION #
# IS PROVIDED "AS-IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, #
# INCLUDING BUT NOT LIMITED TO AN IMPLIED WARRANTY OF MERCHANTABILITY AND/OR #
# FITNESS FOR A PARTICULAR PURPOSE. #
#####################################################################################
# First add a reference to the MWA dll
$dll=[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
#Get the manager and config object
$mgr = new-object Microsoft.Web.Administration.ServerManager
$conf = $mgr.GetApplicationHostConfiguration()
#Get the webFarms section
$section = $conf.GetSection("webFarms")
$webFarms = $section.GetCollection()
foreach ($webFarm in $webFarms)
{
$Name= $webFarm.GetAttributeValue("name");
#Get the servers in the farm
$servers = $webFarm.GetCollection()
Write-Host "Farm Name: " $Name
foreach($server in $servers)
{
$ip= $server.GetAttributeValue("address")
#Get the ARR section
$arr = $server.GetChildElement("applicationRequestRouting")
$counters = $arr.GetChildElement("counters")
$isHealthy=$counters.GetAttributeValue("isHealthy")
$state= $counters.GetAttributeValue("state")
switch ($state)
{
0 {$state= "Available"}
1 {$state= "Drain"}
2 {$state= "Unavailable"}
default {$state= "Non determinato"}
}
if( $isHealthy)
{
$isHealthy="Healthy"
}
else
{
$isHealthy="Not Healthy"
}
Write-Host -NoNewLine $ip " " $state " " $isHealthy
#NEW LINE
Write-Host
}
#NEW LINE
Write-Host
}
Output shows all web farms installed on your server plus the status of each application server.
Enjoy your script
HTH
Carmelo
Comments
- Anonymous
October 01, 2013
Hi,Very interesting information. I have been working with WFF with great satisfaction since 2011 and was wondering since the begining if we could get out these statistics.Your method here reaches out to statistics for Application Request Routing Server counters.Do you know how to get to counters from Application Request Routing Cache ?I was thinking of having to address a friend of Microsoft.Web.Administration.ServerManager but couldn't figure out which one ... As we need to address a different collection of webFarms object.Already thank you.