PerformanceCounterConfiguration.CounterSpecifier Property

 

Gets or sets a performance counter specifier using Windows performance counter syntax.

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

Syntax

public string CounterSpecifier { get; set; }
public:
property String^ CounterSpecifier {
    String^ get();
    void set(String^ value);
}
member CounterSpecifier : string with get, set
Public Property CounterSpecifier As String

Property Value

Type: System.String

Type: System.String

Returns String.

Remarks

The CounterSpecifier property indicates the performance counter you want to monitor. See Performance Counters for ASP.NET for more information on performance counters.

Performance counters will be transferred to the WADPerformanceCounters table in persistent storage at the specified interval.

Example

The following code snippet demonstrates how to use PerformanceCounterConfiguration in the context of remotely changing the diagnostic monitor configuration for each instance of a specific role. This example creates two new PerformanceCounterConfiguration objects, specifies the performance counter and sample rate, gets a RoleInstanceDiagnosticManager object for each instance, and changes the configuration of each role instance using a DiagnosticMonitorConfiguration object.

// 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 appliation 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);

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

// Add a performance counter for processor time.
PerformanceCounterConfiguration pccCPU = new PerformanceCounterConfiguration();
pccCPU.CounterSpecifier = @"\Processor(_Total)\% Processor Time";
pccCPU.SampleRate = perfSampleRate;

// Add a performance counter for available memory.
PerformanceCounterConfiguration pccMemory = new PerformanceCounterConfiguration();
pccMemory.CounterSpecifier = @"\Memory\Available Mbytes";
pccMemory.SampleRate = perfSampleRate;

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

   currentConfiguration.PerformanceCounters.DataSources.Add(pccCPU);
   currentConfiguration.PerformanceCounters.DataSources.Add(pccMemory);

   roleInstance.SetCurrentConfiguration(currentConfiguration);
}

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

PerformanceCounterConfiguration Class
Microsoft.WindowsAzure.Diagnostics Namespace

Return to top