Using WMI to Deliver ASP.NET Health Monitoring Events

One way to monitor the ASP.NET health events is to use the Windows Management Instrumentation (WMI) event provider, WmiWebEventProvider. This provider converts Web health monitoring events (Web events) to WMI events. WMI provides a standard object model in which the entities you want to monitor can be represented as objects. These entities represent computers, network cards, printers, software applications, and so on. These entities are mapped into the WMI object model so that they can be monitored by custom applications. The following illustration shows the relationship between the ASP.NET Web events, WMI, and a consumer application that listens for WMI events.

Relationship between ASP.NET and WMI

WMI Architecture

Connection Between Health Events and WMI

ASP.NET health monitoring provides the infrastructure for the connection between health events and WMI. It does so by mapping these events into the WMI classes so that they can be treated as WMI objects. It also provides the support to process the health events and dispatch them to the WMI system. For details about how to map ASP.NET events to WMI, see Walkthrough: Listening for WMI Events in ASP.NET Health Monitoring. For more information about WMI, see Windows Management Instrumentation in the Platform SDK on MSDN.

The following list describes the steps required to monitor health events with WMI:

  1. Define the mapping between the Web event classes and WMI objects. This step is already done for you for each of the standard Web event classes. These mappings are contained in the Managed Object Format (MOF) file for ASP.NET, %SystemRoot%\Microsoft.NET\Framework\<version>\aspnet.mof file.

    NoteNote

    All custom events are mapped to the base event type in WMI. It is not possible to map a custom ASP.NET health monitoring event to an arbitrary WMI event.

    For example, the following code shows the definition of the WMI class mapped to the WebHeartBeatEvent type.

    class HeartbeatEvent : ManagementEvent {
        /*
         * ProcessStatistics    
         */
        DATETIME    ProcessStartTime;
        sint32      ThreadCount;
        sint64      WorkingSet;
        sint64      PeakWorkingSet;
        sint64      ManagedHeapSize;
        sint32      AppdomainCount;    
        sint32      RequestsExecuting;
        sint32      RequestsQueued;
        sint32      RequestsRejected;
    };
    

    For more information about MOF files, see Managed Object Format in the WMI SDK in MSDN.

  2. Define an ASP.NET health monitoring provider responsible for processing the events.

    The standard provider is WmiWebEventProvider, which is already configured by default in the healthMonitoring section of the root Web.config file using the following code.

    <providers>
      <add 
        name="WmiWebEventProvider" 
        type="System.Web.Management.WmiWebEventProvider,System.Web, Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" 
      />
    </providers>
    
  3. Enter the appropriate settings in the healthMonitoring section of the configuration file to create the association between Web event classes and the WMI event provider, WmiWebEventProvider.

    By default, there are no Web events subscribed to by the WMI event provider. You can use the following code in an application-level Web.config file to subscribe WMI event provider to all Web events. The All Events event type is configured by default in the eventMappings element in the root Web.config file, and is mapped to the WebBaseEvent class.

    <rules>
      <add 
        name="Testing Wmi"
        eventName="All Events" 
        provider="WmiWebEventProvider" 
        profile="Critical"
      />
    </rules>
    
  4. Create an application to listen for WMI events, or use a third-party application.

    The code example in Walkthrough: Listening for WMI Events in ASP.NET Health Monitoring creates a console application that displays event information whenever a Web event is raised.

Customizing the WMI Health Events Infrastructure

When a Web event occurs, ASP.NET health monitoring dispatches it to the WmiWebEventProvider object that processes it, fills in the appropriate data according to the related MOF class definition, and then dispatches this data to the WMI system, using a call to unmanaged code.

The only customization option for sending Web events to WMI is if you create your own custom application that consumes ASP.NET health monitoring events after they have been issued as WMI events. In this case, the only configuration change you need to make is to configure a new rules element as listed above. Your application will listen for the ASP.NET health events in the form of WMI events, as issued by the operating system. For more information, see Walkthrough: Listening for WMI Events in ASP.NET Health Monitoring.

NoteNote

You cannot extend the WmiWebEventProvider class. The only event provider classes that you can extend are the WebEventProvider and BufferedWebEventProvider classes.

See Also

Tasks

Walkthrough: Listening for WMI Events in ASP.NET Health Monitoring

Reference

healthMonitoring Element (ASP.NET Settings Schema)
WmiWebEventProvider