WebProcessStatistics 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供評估執行中處理序健康狀態所需的資訊。
public ref class WebProcessStatistics
public class WebProcessStatistics
type WebProcessStatistics = class
Public Class WebProcessStatistics
- 繼承
-
WebProcessStatistics
範例
下列程式碼範例有兩個部分。 第一個是組態檔的摘錄,可讓 ASP.NET 使用使用 WebProcessStatistics 類型的自訂事件。 第二個顯示如何實作這個自訂事件。
請確定您的自訂事件會在適當的時間引發,也就是說,它會引發其取代的對等系統健康情況事件。
<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());
}
}
}
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
' 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
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
End Class
備註
ASP.NET 健康情況監視可讓生產與作業人員管理已部署的 Web 應用程式。 System.Web.Management命名空間包含負責封裝應用程式健康狀態資料的健全狀況事件種類,以及負責處理此資料的提供者類型。 它也包含支援類型,可協助管理健康情況事件。
類別的 WebProcessStatistics 實例包含使用 WebHeartbeatEvent 型別取得的資訊。
注意
在大部分情況下,您將能夠使用實作 ASP.NET 健康情況監視類型,而且您會在組態區段中指定值 healthMonitoring
來控制健康情況監視系統。 您也可以從健康情況監視類型衍生,以建立您自己的自訂事件和提供者。 如需建立自訂事件類別的範例,請參閱本主題中提供的範例。
以下是可用來啟用 ASP.NET 記錄包含進程統計資料的活動訊號事件的組態檔摘要。
<healthMonitoring
enabled="true" heartBeatInterval="100">
<rules>
<add
name="Process Statistics"
eventName="Heartbeats"
provider="EventLogProvider"
profile="Default"/>
</rules>
</healthMonitoring>
建構函式
WebProcessStatistics() |
初始化 WebProcessStatistics 類別的新執行個體。 |
屬性
AppDomainCount |
取得處理序中的應用程式定義域個數。 |
ManagedHeapSize |
取得 Managed 堆積的大小。 |
PeakWorkingSet |
取得處理序執行到目前為止整個過程中的尖峰工作集。 |
ProcessStartTime |
取得處理序啟動的時間。 |
RequestsExecuting |
取得目前執行中的要求個數。 |
RequestsQueued |
取得等待處理之要求的個數。 |
RequestsRejected |
取得被拒絕之要求的個數。 |
ThreadCount |
取得處理序執行緒的總計數。 |
WorkingSet |
取得處理序的工作集。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
FormatToString(WebEventFormatter) |
將處理序統計資料安排成適當格式。 |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |