WmiWebEventProvider Klasa

Definicja

Implementuje dostawcę zdarzeń, który mapuje zdarzenia monitorowania kondycji ASP.NET na zdarzenia instrumentacji zarządzania Windows (WMI).

public ref class WmiWebEventProvider : System::Web::Management::WebEventProvider
public class WmiWebEventProvider : System.Web.Management.WebEventProvider
type WmiWebEventProvider = class
    inherit WebEventProvider
Public Class WmiWebEventProvider
Inherits WebEventProvider
Dziedziczenie
WmiWebEventProvider

Przykłady

W poniższym przykładzie pokazano, jak utworzyć użytkownika zdarzeń usługi WMI wystawionych przez monitorowanie kondycji ASP.NET w wyniku zdarzeń kondycji aplikacji internetowej.

Uwaga

Klasa WmiWebEventProvider i typy zdarzeń kondycji do monitorowania są już domyślnie skonfigurowane. Jedyną rzeczą, którą należy wykonać, jest zdefiniowanie reguły dla wszystkich zdarzeń kondycji. Pamiętaj, że zdarzenia kondycji nie są domyślnie wysyłane do dostawcy WmiWebEventProvider .


using System;
using System.Management;

namespace SamplesAspNet
{
    // Capture WMI events associated with 
    // ASP.NET health monitoring types. 
    class SampleWmiWebEventListener
    {
        //Displays event related information.
        static void DisplayEventInformation(
            ManagementBaseObject ev)
        {

            // It contains the name of the WMI raised 
            // event. This is the name of the 
            // event class as defined in the 
            // Aspnet.mof file.
            string eventTypeName;

            // Get the name of the WMI raised event.
            eventTypeName = ev.ClassPath.ToString();

            // Process the raised event.
            switch (eventTypeName)
            {
                // Process the heartbeat event.  
                case "HeartBeatEvent":
                    Console.WriteLine("HeartBeat");
                    Console.WriteLine("\tProcess: {0}", 
                        ev["ProcessName"]);
                    Console.WriteLine("\tApp: {0}", 
                        ev["ApplicationUrl"]);
                    Console.WriteLine("\tWorkingSet: {0}", 
                        ev["WorkingSet"]);
                    Console.WriteLine("\tThreads: {0}", 
                        ev["ThreadCount"]);
                    Console.WriteLine("\tManagedHeap: {0}",
                        ev["ManagedHeapSize"]);
                    Console.WriteLine("\tAppDomainCount: {0}",
                        ev["AppDomainCount"]);
                    break;

                // Process the request error event. 
                case "RequestErrorEvent":
                    Console.WriteLine("Error");
                    Console.WriteLine("Url: {0}", 
                        ev["RequestUrl"]);
                    Console.WriteLine("Path: {0}", 
                        ev["RequestPath"]);
                    Console.WriteLine("Message: {0}", 
                        ev["EventMessage"]);
                    Console.WriteLine("Stack: {0}", 
                        ev["StackTrace"]);
                    Console.WriteLine("UserName: {0}", 
                        ev["UserName"]);
                    Console.WriteLine("ThreadID: {0}", 
                        ev["ThreadAccountName"]);
                    break;

                // Process the application lifetime event. 
                case "ApplicationLifetimeEvent":
                    Console.WriteLine("App Lifetime Event {0}", 
                        ev["EventMessage"]);
                   
                    break;

                // Handle events for which processing is not
                // provided.
                default:
                    Console.WriteLine("ASP.NET Event {0}",
                        ev["EventMessage"]);
                    break;
            }
        } // End DisplayEventInformation.

        // The main entry point for the application.
        static void Main(string[] args)
        {
            // Get the name of the computer on 
            // which this program runs.
            // Note. The monitored application must also run 
            // on this computer.
            string machine = Environment.MachineName;

            // Define the Common Information Model (CIM) path 
            // for WIM monitoring. 
            string path = String.Format("\\\\{0}\\root\\aspnet", 
                machine);

            // Create a managed object watcher as 
            // defined in System.Management.
            string query = "select * from BaseEvent";
            ManagementEventWatcher watcher =
                new ManagementEventWatcher(query);

            // Set the watcher options.
            TimeSpan timeInterval = new TimeSpan(0, 1, 30);
            watcher.Options = 
                new EventWatcherOptions(null,
                timeInterval, 1);

            // Set the scope of the WMI events to 
            // watch to be ASP.NET applications.
            watcher.Scope = 
                new ManagementScope(new ManagementPath(path));

            // Set the console background.
            Console.BackgroundColor = ConsoleColor.Blue;
            // Set foreground color.
            Console.ForegroundColor = ConsoleColor.Yellow;
            // Clear the console.
            Console.Clear();

            // Loop indefinitely to catch the events.
            Console.WriteLine(
                "Listener started. Enter CntlC to terminate");

            while (true)
            {
                try
                {
                    // Capture the WMI event related to 
                    // the Web event.
                    ManagementBaseObject ev = 
                        watcher.WaitForNextEvent();
                    // Display the Web event information.
                    DisplayEventInformation(ev);

                    // Prompt the user.
                    Console.Beep();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: {0}", e);
                    break;
                }
            }
        }
    }
}
Imports System.Management



' Capture WMI events associated with 
' ASP.NET health monitoring types. 

Class SampleWmiWebEventListener
    
    'Displays event related information.
    Shared Sub DisplayEventInformation(ByVal ev _
As ManagementBaseObject)

        ' It contains the name of the WMI raised 
        ' event. This is the name of the 
        ' event class as defined in the 
        ' Aspnet.mof file.
        Dim eventTypeName As String

        ' Get the name of the WMI raised event.
        eventTypeName = ev.ClassPath.ToString()

        ' Process the raised event.
        Select Case eventTypeName
            ' Process the heartbeat event.  
            Case "HeartBeatEvent"
                Console.WriteLine("HeartBeat")
                Console.WriteLine(vbTab + _
                "Process: {0}", ev("ProcessName"))
                Console.WriteLine(vbTab + "App: {0}", _
                ev("ApplicationUrl"))
                Console.WriteLine(vbTab + "WorkingSet: {0}", _
                ev("WorkingSet"))
                Console.WriteLine(vbTab + "Threads: {0}", _
                ev("ThreadCount"))
                Console.WriteLine(vbTab + "ManagedHeap: {0}", _
                ev("ManagedHeapSize"))
                Console.WriteLine(vbTab + "AppDomainCount: {0}", _
                ev("AppDomainCount"))

                ' Process the request error event. 
            Case "RequestErrorEvent"
                Console.WriteLine("Error")
                Console.WriteLine("Url: {0}", _
                ev("RequestUrl"))
                Console.WriteLine("Path: {0}", _
                ev("RequestPath"))
                Console.WriteLine("Message: {0}", _
                ev("EventMessage"))
                Console.WriteLine("Stack: {0}", _
                ev("StackTrace"))
                Console.WriteLine("UserName: {0}", _
                ev("UserName"))
                Console.WriteLine("ThreadID: {0}", _
                ev("ThreadAccountName"))

                ' Process the application lifetime event. 
            Case "ApplicationLifetimeEvent"
                Console.WriteLine("App Lifetime Event {0}", _
                ev("EventMessage"))


                ' Handle events for which processing is not
                ' provided.
            Case Else
                Console.WriteLine("ASP.NET Event {0}", _
                ev("EventMessage"))
        End Select

    End Sub

    ' End DisplayEventInformation.
    ' The main entry point for the application.
    Shared Sub Main(ByVal args() As String)
        ' Get the name of the computer on 
        ' which this program runs.
        ' Note. The monitored application must also run 
        ' on this computer.
        Dim machine As String = Environment.MachineName

        ' Define the Common Information Model (CIM) path 
        ' for WIM monitoring. 
        Dim path As String = _
        String.Format("\\{0}\root\aspnet", machine)

        ' Create a managed object watcher as 
        ' defined in System.Management.
        Dim query As String = "select * from BaseEvent"
        Dim watcher As New ManagementEventWatcher(query)

        ' Set the watcher options.
        Dim timeInterval As New TimeSpan(0, 1, 30)
        watcher.Options = _
        New EventWatcherOptions(Nothing, timeInterval, 1)

        ' Set the scope of the WMI events to 
        ' watch to be ASP.NET applications.
        watcher.Scope = _
        New ManagementScope(New ManagementPath(path))

        ' Set the console background.
        Console.BackgroundColor = ConsoleColor.Blue
        ' Set foreground color.
        Console.ForegroundColor = ConsoleColor.Yellow
        ' Clear the console.
        Console.Clear()

        ' Loop indefinitely to catch the events.
        Console.WriteLine( _
        "Listener started. Enter CntlC to terminate")


        While True
            Try
                ' Capture the WMI event related to 
                ' the Web event.
                Dim ev As ManagementBaseObject = _
                watcher.WaitForNextEvent()
                ' Display the Web event information.
                DisplayEventInformation(ev)

                ' Prompt the user.
                Console.Beep()

            Catch e As Exception
                Console.WriteLine("Error: {0}", e)
                Exit While
            End Try
        End While

    End Sub
End Class

Poniższy przykład to fragment pliku konfiguracji przedstawiający sekcję <healthMonitoring> konfiguracji, która umożliwia ASP.NET używanie WmiWebEventProvider dostawcy do przetwarzania wszystkich zdarzeń monitorowania kondycji.

<healthMonitoring>  
  <rules>  
    <add   
      name="Using Wmi"  
      eventName="All Events"   
      provider="WmiWebEventProvider"   
      profile="Critical"/>  
  </rules>  
</healthMonitoring>  

Uwagi

ASP.NET monitorowanie kondycji umożliwia personelowi produkcyjnemu i operacyjnemu zarządzanie wdrożonych aplikacji internetowych. System.Web.Management Przestrzeń nazw zawiera typy zdarzeń kondycji odpowiedzialnych za pakowanie danych o stanie kondycji aplikacji i typów dostawców odpowiedzialnych za przetwarzanie tych danych. Zawiera również typy pomocnicze, które ułatwiają zarządzanie zdarzeniami kondycji.

ASP.NET używa tej klasy do mapowania zdarzeń monitorowania kondycji na zdarzenia usługi WMI. Aby umożliwić dostarczanie ASP.NET zdarzeń monitorowania kondycji do podsystemu WMI, należy skonfigurować klasęWmiWebEventProvider, dodając odpowiednie ustawienia w <healthMonitoring> sekcji pliku konfiguracji.

Informacje zawarte w pliku Aspnet.mof opisują parametry zdarzeń usługi WMI zgłaszanych, gdy ASP.NET zdarzenia monitorowania kondycji są kierowane do WmiWebEventProvider klasy i mapowane na zdarzenia usługi WMI. Plik Aspnet.mof jest przechowywany w katalogu kompilacji .NET Framework, na przykład %windir%\Microsoft.NET*FrameworkBuildNumber*\. Aby uzyskać więcej informacji na temat raportowania zdarzeń monitorowania kondycji jako zdarzeń usługi WMI, zobacz Używanie usługi WMI do dostarczania zdarzeń monitorowania kondycji ASP.NET.

Uwaga

W większości przypadków będzie można użyć ASP.NET typów monitorowania kondycji zgodnie z implementacją i będziesz kontrolować system monitorowania kondycji, określając wartości w <healthMonitoring> sekcji konfiguracji. Możesz również pochodzić z typów monitorowania kondycji, aby utworzyć własne niestandardowe zdarzenia i dostawców. Przykład tworzenia dostawcy niestandardowego można znaleźć w temacie How to: Implement the Health Monitoring Custom Provider Example (Instrukcje: implementowanie niestandardowego dostawcy monitorowania kondycji).

Konstruktory

WmiWebEventProvider()

Inicjuje nowe wystąpienie klasy WmiWebEventProvider.

Właściwości

Description

Pobiera krótki, przyjazny opis odpowiedni do wyświetlania w narzędziach administracyjnych lub innych interfejsach użytkownika (UI).

(Odziedziczone po ProviderBase)
Name

Pobiera przyjazną nazwę używaną do odwoływania się do dostawcy podczas konfiguracji.

(Odziedziczone po ProviderBase)

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
Flush()

Usuwa wszystkie zdarzenia z buforu dostawcy.

GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
Initialize(String, NameValueCollection)

Ustawia początkowe wartości dla tego obiektu.

MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ProcessEvent(WebBaseEvent)

Przetwarza zdarzenie przekazane do dostawcy.

Shutdown()

Wykonuje zadania skojarzone z zamykaniem dostawcy.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też