导出 (0) 打印
全部展开

DiagnosticMonitorConfiguration.PerformanceCounters 属性

更新时间: 2013年12月

获取或设置性能计数器数据的缓冲区配置。

命名空间: Microsoft.WindowsAzure.Diagnostics
程序集: Microsoft.WindowsAzure.Diagnostics(在 Microsoft.WindowsAzure.Diagnostics.dll 中)

public PerformanceCountersBufferConfiguration PerformanceCounters { get; set; }

属性值

类型:Microsoft.WindowsAzure.Diagnostics.PerformanceCountersBufferConfiguration

返回 PerformanceCountersBufferConfiguration

Diagnostics.wadcfg 文件用于在应用程序中配置诊断。有关如何配置 diagnostics.wadcfg 文件的详细信息,请参阅 Enabling Diagnostics in Windows Azure。你的应用程序在 Microsoft Azure 中运行后,你可以同时使用 DiagnosticMonitorConfiguration 类和 RoleInstanceDiagnosticManager 类来远程更改应用程序诊断配置。

使用 PerformanceCounters 属性可以指定用于捕获性能度量值的 PerformanceCountersBufferConfiguration 数据缓冲区。使用此属性可以在 DataSources 集合中添加性能计数器。还可以使用它来指定默认的数据缓冲区属性:BufferQuotaInMBScheduledTransferPeriod

Example

以下代码段将获取角色中每个实例的诊断监视器配置,指定性能计数器的配置,然后设置新的配置。

// Get the connection string. It's recommended that you store the connection string in your web.config or app.config file.
// Use the ConfigurationManager type to retrieve your storage connection string.  You can find the account name and key in
// the Windows Azure Management Portal (http://manage.windowsazure.com).
//string connectionString = "DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<AccountKey>";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;

// The deployment ID and role name for your application can be obtained from the 
// Windows Azure Management Portal (http://manage.windowsazure.com). See your 
// application dashboard under Cloud Services.
string deploymentID = "e2ab8b6667644666ba627bdf6f5e4daa";
string roleName = "WebRole1";

// Get the DeploymentDiagnosticManager object for your deployment.
DeploymentDiagnosticManager diagManager = new DeploymentDiagnosticManager(connectionString, deploymentID);

// Get the RoleInstanceDiagnosticManager objects for each instance of your role.
IEnumerable<RoleInstanceDiagnosticManager> instanceManagers = diagManager.GetRoleInstanceDiagnosticManagersForRole(roleName);

// Iterate through the role instances and update the configuration.
foreach (RoleInstanceDiagnosticManager roleInstance in instanceManagers)
{
   DiagnosticMonitorConfiguration diagnosticConfiguration = roleInstance.GetCurrentConfiguration();

   // Use 30 seconds for the performance counter sample rate.
   TimeSpan perfSampleRate = TimeSpan.FromSeconds(30.0);

   // Add a performance counter for requests per second.
   diagnosticConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
   {
      CounterSpecifier = @"\ASP.NET\Requests/Sec",
      SampleRate = perfSampleRate
   });

   // Transfer the counters every 30 minutes.
   diagnosticConfiguration.PerformanceCounters.ScheduledTransferPeriod = perfSampleRate;

   // Set the configuration.
   roleInstance.SetCurrentConfiguration(diagnosticConfiguration);
}
Warning警告
Azure SDK 2.5 和更高版本不支持此 API。请改用 diagnostics.wadcfg XML 配置文件。有关详细信息,请参阅Collect Logging Data by Using Azure Diagnostics


此类型的所有公开静态(在 Visual Basic 中为共享)成员均为线程安全型成员。但不保证所有实例成员都是线程安全的。

开发平台

Windows Vista、Windows 7 和 Windows Server 2008

目标平台

社区附加资源

添加
Microsoft 正在进行一项网上调查,以了解您对 MSDN 网站的意见。 如果您选择参加,我们将会在您离开 MSDN 网站时向您显示该网上调查。

是否要参加?
显示:
© 2015 Microsoft