For those who are not aware, IIS is a HTTP web server from Microsoft which can host both static and dynamic content. This is done by a Windows kernel-mode driver named http.sys. It listens for incoming TCP requests on a configured port, performs some basic security checks and passes the request to a user-mode process. The worker fulfills the request and sends the response back to the requester. Web application are grouped into IIS application pools which has it’s own process assigned to it.
As we are migrated al our IIS applications to a new IIS 8.5 farm on Windows 2012 R2 servers, we needed a way to reliably monitor the state of our most critical IIS application pools. So I created a Powershell script which is able to check the state of an application pool and count the number of web application using it. As each IIS application pool has one w3wp.exe IIS worker process assigned, I added the % processor usage and memory usage to the perfdata.
The latest version also contains a new method to retrieve the IIS application pool information. As Get-ChildItem IIS:\AppPools has a weird bug where the command hangs sometimes I had to look for an alternative. This method uses C:\Windows\system32\inetsrv\appcmd.exe instead, which seems much more performant.
How to monitor your MS IIS Application Pools with Nagios?
- Put the script in the NSClient++ scripts folder, preferably in a subfolder Powershell.
- In the nsclient.ini configuration file, define the script like this:
1check_ms_iis_application_pool=cmd /c echo scripts/powershell/check_ms_iis_application_pool.ps1 $ARG1$; exit $LastExitCode | powershell.exe /noprofile -command -
- Make a command in Nagios like this:
1check_ms_iis_application_pool => $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -t 60 -c check_ms_iis_application_pool $ARG1$
- Configure your service in Nagios. Make use of the above created command. Configure something similar like this as $ARG1$:
1-a '-A <Name-Of-Application-Pool>'
Or if you want to monitor an application pool which has OnDemand startmode where there is no IIS worker process when it isn’t used.
1-a '-A <Name-Of-Application-Pool>' -APOD 1
When you want to use the AppCmd.exe method:
1-a '-A <Name-Of-Application-Pool>' -AppCmd 1
I only had the chance to test this on a Windows Server 2012 R2. It’s very possible you will experience issues on lower IIS versions. You need to install the IIS Management Scripts and Tools feature for the script to work properly.
When you got it up and running your Nagios server should look like this: