WebProcessStatistics Class
Assembly: System.Web (in system.web.dll)
ASP.NET health monitoring allows production and operations staff to manage deployed Web applications. The System.Web.Management namespace contains the health-event types responsible for packaging application health-status data and the provider types responsible for processing this data. It also contains supporting types that help during the management of health events.
Instances of the WebProcessStatistics class contain information that is obtained using the WebHeartBeatEvent type.
Note: |
|---|
| In most cases you will be able to use the ASP.NET health-monitoring types as implemented, and you will control the health-monitoring system by specifying values in the healthMonitoring configuration section. You can also derive from the health-monitoring types to create your own custom events and providers. For an example of creating a custom event class, see the example provided in this topic. |
The following is an excerpt of a configuration file you could use to enable ASP.NET to log heartbeat events that contain process statistics.
<healthMonitoring
enabled="true" heartBeatInterval="100">
<rules>
<add
name="Process Statistics"
eventName="Heartbeats"
provider="EventLogProvider"
profile="Default"/>
</rules>
</healthMonitoring>
The following code example has two parts. The first is an excerpt of the configuration file that enables ASP.NET to use a custom event that uses the WebProcessStatistics type. The second shows how to implement this custom event..
Ensure that your custom event is raised at the proper time, that is, when the equivalent system health event it replaces would be raised.
<healthMonitoring
enabled="true" heartBeatInterval="0">
<eventMappings>
<add name="SampleProcessStatistics" type="SamplesAspNet.SampleWebProcessStatistics, webprocessstatistics, Version=1.0.1585.27289, Culture=neutral, PublicKeyToken=3648e5c763a8239f, processorArchitecture=MSIL"/>
</eventMappings>
<rules>
<add
name="Custom Process Statistics"
eventName="SampleProcessStatistics"
provider="EventLogProvider"
profile="Default"/>
</rules>
</healthMonitoring>
Imports System Imports System.Text Imports System.Web Imports System.Web.Management ' Implements a custom WebBaseEvent type that ' uses the WebProcessStatistics. Public Class SampleWebProcessStatistics Inherits WebBaseEvent Private eventInfo As StringBuilder Private Shared processStatistics As WebProcessStatistics ' Instantiate the SampleWebProcessStatistics ' type. Public Sub New(ByVal msg As String, ByVal eventSource As Object, ByVal eventCode As Integer) MyBase.New(msg, eventSource, eventCode) ' Perform custom initialization. Dim customMsg As String = String.Format("Event created at: {0}", EventTime.ToString()) eventInfo = New StringBuilder() eventInfo.AppendLine(customMsg) ' Instantiate the WebProcessStatistics ' type. processStatistics = New WebProcessStatistics() End Sub 'New ' Raises the event. Public Overrides Sub Raise() ' Perform custom processing. eventInfo.Append(String.Format( _ "Event raised at: {0}" + _ ControlChars.Lf, EventTime.ToString())) ' Raise the event. MyBase.Raise() End Sub 'Raise Public Function GetAppDomainCount() As String ' Get the app domain count. Return String.Format( _ "Application domain count: {0}", _ processStatistics.AppDomainCount.ToString()) End Function 'GetAppDomainCount Public Function GetManagedHeapSize() As String ' Get the mamaged heap size. Return String.Format( _ "Managed heap size: {0}", _ processStatistics.ManagedHeapSize.ToString()) End Function 'GetManagedHeapSize Public Function GetPeakWorkingSet() As String ' Get the peak working set. Return String.Format( _ "Peak working set: {0}", _ processStatistics.PeakWorkingSet.ToString()) End Function 'GetPeakWorkingSet Public Function GetProcessStartTime() As String ' Get the process start time. Return String.Format( _ "Process start time: {0}", _ processStatistics.ProcessStartTime.ToString()) End Function 'GetProcessStartTime Public Function GetRequestsExecuting() As String ' Get the requests in execution. Return String.Format( _ "Requests executing: {0}", _ processStatistics.RequestsExecuting.ToString()) End Function 'GetRequestsExecuting Public Function GetRequestsQueued() As String ' Get the requests queued. Return String.Format( _ "Requests queued: {0}", _ processStatistics.RequestsQueued.ToString()) End Function 'GetRequestsQueued Public Function GetRequestsRejected() As String ' Get the requests rejected. Return String.Format( _ "Requests rejected: {0}", _ processStatistics.RequestsRejected.ToString()) End Function 'GetRequestsRejected Public Function GetThreadCount() As String ' Get the thread count. Return String.Format( _ "Thread count: {0}", _ processStatistics.ThreadCount.ToString()) End Function 'GetThreadCount Public Function GetWorkingSet() As String ' Get the working set. Return String.Format( _ "Working set: {0}", _ processStatistics.WorkingSet.ToString()) End Function 'GetWorkingSet 'Formats Web request event information. Public Overrides Sub FormatCustomEventDetails( _ ByVal formatter As WebEventFormatter) MyBase.FormatCustomEventDetails(formatter) ' Add custom data. formatter.AppendLine("") formatter.AppendLine("Custom Process Statistics:") formatter.IndentationLevel += 1 ' Get the process statistics. formatter.AppendLine(GetAppDomainCount()) formatter.AppendLine(GetManagedHeapSize()) formatter.AppendLine(GetPeakWorkingSet()) formatter.AppendLine(GetProcessStartTime()) formatter.AppendLine(GetRequestsExecuting()) formatter.AppendLine(GetRequestsQueued()) formatter.AppendLine(GetRequestsRejected()) formatter.AppendLine(GetThreadCount()) formatter.AppendLine(GetWorkingSet()) formatter.IndentationLevel -= 1 formatter.AppendLine(eventInfo.ToString()) End Sub 'FormatCustomEventDetails End Class 'SampleWebEventHelper
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Note: