Create an IIS web request activity light

89 views Asked by At

Is it possible to create an activity / blinking light on the windows desktop that indicates when an IIS webpage request comes in? We are looking to find some kind of indicator of requests per minute on our server, kind of like a blinking light you would see when a hard drive is performing heavy I/O operations. This would be a software blinking light however, and would be a nice easy way to see current website activity.

1

There are 1 answers

0
Cyril Durand On

I can see two solution:

  1. You can access some IIS information using performance counters. The Requests / Sec counter of W3SVC_W3WP group will give you the number of request the IIS server respond per second. See New worker process performance counters in IIS7 for more information on available IIS performance counter.

    var counter = new PerformanceCounter("W3SVC_W3WP", "Requests / Sec", "_Total", true);
    while (true)
    {
        var requestPerSecond = (Int32)counter.NextValue();
    
        // do whatever you want
    
        Console.WriteLine(requestPerSecond);
        Thread.Sleep(1000);
    }
    
  2. If you want to blink a virtual led for each request, the previous solution won't be enough. You can intercept a query by using a custom IHttpModule that will communicate with your virtual led.

    public class BlinkModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.EndRequest += context_EndRequest;
        }
    
        private void context_EndRequest(Object sender, EventArgs e)
        {
            Task.Run(() =>
            {
                // call your virtual led using named pipe or whatever you want 
            });
        }
    
        public void Dispose()
        { }
    }
    

    Your virtual led application should have a mechanism that will let it blink from an external application, you can do this using a WCF service with named pipe binding for example.