DiagnosticMonitorConfiguration.PerformanceCounters Property

 

Gets or sets the buffer configuration for performance counter data.

Namespace:   Microsoft.WindowsAzure.Diagnostics
Assembly:  Microsoft.WindowsAzure.Diagnostics (in Microsoft.WindowsAzure.Diagnostics.dll)

Syntax

public PerformanceCountersBufferConfiguration PerformanceCounters { get; set; }
public:
property PerformanceCountersBufferConfiguration^ PerformanceCounters {
    PerformanceCountersBufferConfiguration^ get();
    void set(PerformanceCountersBufferConfiguration^ value);
}
member PerformanceCounters : PerformanceCountersBufferConfiguration with get, set
Public Property PerformanceCounters As PerformanceCountersBufferConfiguration

Property Value

Type: Microsoft.WindowsAzure.Diagnostics.PerformanceCountersBufferConfiguration

Type: Microsoft.WindowsAzure.Diagnostics.PerformanceCountersBufferConfiguration

Returns PerformanceCountersBufferConfiguration.

Remarks

The diagnostics.wadcfg file is used to configure diagnostics in your application. For more information on how to configure your diagnostics.wadcfg file, see Enabling Diagnostics in Windows Azure. Once your application is running in Windows Azure, you can use the DiagnosticMonitorConfiguration class along with the RoleInstanceDiagnosticManager class to remotely change your application’s diagnostics configuration.

The PerformanceCounters property is used to specify the PerformanceCountersBufferConfiguration data buffer that is used for capturing performance metrics. This property enables you to add performance counters to the DataSources collection. You can also use it to specify the default data buffer properties: BufferQuotaInMB and ScheduledTransferPeriod.

Example

The following code snippet gets diagnostic monitor configuration for each instance in a role, specifies the configuration for performance counters, then sets the new configuration.

// 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 (https://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 (https://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

This API is not supported in Azure SDK versions 2.5 and higher. Instead, use the diagnostics.wadcfg XML configuration file. For more information, see Collect Logging Data by Using Azure Diagnostics.

See Also

DiagnosticMonitorConfiguration Class
Microsoft.WindowsAzure.Diagnostics Namespace

Return to top