Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

WebProcessStatistics Class

Provides information for assessing the health of a running process.

System.Object
  System.Web.Management.WebProcessStatistics

Namespace:  System.Web.Management
Assembly:  System.Web (in System.Web.dll)
public class WebProcessStatistics

The WebProcessStatistics type exposes the following members.

  NameDescription
Public methodWebProcessStatisticsInitializes a new instance of the WebProcessStatistics class.
Top
  NameDescription
Public propertyAppDomainCountGets the number of application domains in the process.
Public propertyManagedHeapSizeGets the size of the managed heap.
Public propertyPeakWorkingSetGets the peak working set for the lifetime of the process to date.
Public propertyProcessStartTimeGets the time when the process started.
Public propertyRequestsExecutingGets the number of requests currently executing.
Public propertyRequestsQueuedGets the number of requests waiting to be processed.
Public propertyRequestsRejectedGets the number of rejected requests.
Public propertyThreadCountGets the total count of the process threads.
Public propertyWorkingSetGets the working set for the process.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFormatToStringFormats the process statistics.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

NoteNote

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>

using System;
using System.Text;
using System.Web;
using System.Web.Management;

namespace SamplesAspNet
{
    // Implements a custom WebBaseEvent type that  
    // uses the WebProcessStatistics. 
    public class SampleWebProcessStatistics :
      WebBaseEvent
    {
        private StringBuilder eventInfo;
        private static WebProcessStatistics processStatistics;

        // Instantiate the SampleWebProcessStatistics 
        // type. 
        public SampleWebProcessStatistics(string msg, 
            object eventSource, int eventCode):
          base(msg, eventSource, eventCode)
        {
            // Perform custom initialization. 
            string customMsg = 
                string.Format("Event created at: {0}", 
                EventTime.ToString());

            eventInfo = new StringBuilder();
            eventInfo.AppendLine(customMsg);

            // Instantiate the WebProcessStatistics  
            // type.
            processStatistics = new WebProcessStatistics();

        }





        // Raises the event. 
        public override void Raise()
        {
            // Perform custom processing. 
            eventInfo.Append(
                string.Format(
                "Event raised at: {0}\n", EventTime.ToString()));
            // Raise the event. 
            base.Raise();
        }

        public string GetAppDomainCount()
        {
            // Get the app domain count. 
            return (string.Format(
                "Application domain count: {0}",
                processStatistics.AppDomainCount.ToString()));
        }


        public string GetManagedHeapSize()
        {
            // Get the mamaged heap size. 
            return (string.Format(
                "Managed heap size: {0}",
                processStatistics.ManagedHeapSize.ToString()));
        }


        public string GetPeakWorkingSet()
        {
            // Get the peak working set. 
            return (string.Format(
                "Peak working set: {0}",
                processStatistics.PeakWorkingSet.ToString()));
        }


        public string GetProcessStartTime()
        {
            // Get the process start time. 
            return (string.Format(
                "Process start time: {0}",
                processStatistics.ProcessStartTime.ToString()));
        }


        public string GetRequestsExecuting()
        {
            // Get the requests in execution. 
            return (string.Format(
                "Requests executing: {0}",
                processStatistics.RequestsExecuting.ToString()));
        }



        public string GetRequestsQueued()
        {
            // Get the requests queued. 
            return (string.Format(
                "Requests queued: {0}",
                processStatistics.RequestsQueued.ToString()));
        }


        public string GetRequestsRejected()
        {
            // Get the requests rejected. 
            return (string.Format(
                "Requests rejected: {0}",
                processStatistics.RequestsRejected.ToString()));
        }


        public string GetThreadCount()
        {
            // Get the thread count. 
            return (string.Format(
                "Thread count: {0}",
                processStatistics.ThreadCount.ToString()));
        }


        public string GetWorkingSet()
        {
            // Get the working set. 
            return (string.Format(
                "Working set: {0}",
                processStatistics.WorkingSet.ToString()));
        }



        //Formats Web request event information. 
        public override void FormatCustomEventDetails(
            WebEventFormatter formatter)
        {
            base.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());

        }


    }

}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.