Monitoring Application Pool and Application Restarts


This morning I found the following in my inbox:


I had set my web servers running on IIS 6 to recycle if they hit 700 MB (Maximum used Memory).
Can I run a report to know how many times per day or week the W3WP got recycled.
Any suggestions please.

Thanks in anticipation



The quick answer to your question is to use performance monitor:



  1. Start performance monitor
  2. Add a new counter
  3. Performance object: "ASP.NET v[n]"
  4. Counter: "Worker Process Restarts"

So, there's the answer. But while we're on the subject I'd like to mention application restarts as well.


Applications vs. Application pools


Application restarts may lead you think that your entire application pool recycled, while in fact it was only one of the applications hosted by the application pool that restarted. If this is getting confusing, then please remember that there's a difference between application pools and application. An application pool will consist of one or several worker processes and may host one or several applications.


There are two easy ways of monitoring application restarts:



  • Using performance monitor again
  • Have ASP.NET write an event to the event log upon shutdown & startup. (Requires ASP.NET 2.0 or later)

Performance monitor


This is probably the easiest, though you won't get too much additional information other than the fact that an application restart occurred. Here's what you do:



  1. Start performance monitor
  2. Add a new counter
  3. Performance object: "ASP.NET v[n]"
  4. Counter: "Application Restarts"

Event log


By altering the root web.config you can get an event for every application shutdown and start up. This is a good way to get more detailed information on why the application shut down.


Open up the root web.config, (located in the %WinDir%\Microsoft.NET\Framework\v2.0.50727\CONFIG directory,) locate the healthMonitoring.rules subkey and add the following:


<add name="Application Lifetime Events Default" eventName="Application Lifetime Events"
provider="EventLogProvider" profile="Default" minInstances="1"
maxLimit="Infinite" minInterval="00:01:00" custom="" />

Now when the application exited for an application-specific reason you'll get an event like this:


Event code: 1002
Event message: Application is shutting down. Reason: Configuration changed.
Event time: 2/14/2008 10:00:41 AM
Event time (UTC): 2/14/2008 9:00:41 AM
Event ID: a1314c10a0c84222ae2d870d85308304
Event sequence: 18
Event occurrence: 1
Event detail code: 50004

Application information:
Application domain: /LM/w3svc/1/ROOT/Test-1-128474532435626182
Trust level: Full
Application Virtual Path: /Test
Application Path: c:\inetpub\wwwroot\Test\
Machine name: JOHAN


As you can see the application shut down because the configuration changed. Note that you won't get an event if you manually kill the entire application pool in IIS manager, or similar. One thing that you will get, however, is the following event each and every time the application starts up again:


Event code: 1001
Event message: Application is starting.
Event time: 2/14/2008 10:00:47 AM
Event time (UTC): 2/14/2008 9:00:47 AM
Event ID: 1f41fd3b17764330ac61804094b0abf0
Event sequence: 1
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/w3svc/1/ROOT/Test-1-128474532435626182
Trust level: Full
Application Virtual Path: /Test
Application Path: c:\inetpub\wwwroot\Test\
Machine name: JOHAN


So even if the application shut down for a reason that didn't generate an event, (IISReset, idle server, etc.) you'll at least see that for some reason it had to start up again.


/ Johan

Comments (5)

  1. Giri says:

    Thanks for the article. Informative and very helpful to me.

  2. exactly what I needed, thanks!

  3. sriharsha says:

    The worker process restarts counter is not working in IIS6 ot 7 it is always showing ZERO.. any other way to know IIS recycle??

  4. Chirag says:

    Is there way to findout how database connection is open by application pool

Skip to main content