Compartilhar via


PerformanceCounterConfiguration Class

 

Represents the configuration for performance counter data sources.

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

Inheritance Hierarchy

System.Object
  Microsoft.WindowsAzure.Diagnostics.PerformanceCounterConfiguration

Syntax

public class PerformanceCounterConfiguration
public ref class PerformanceCounterConfiguration 
type PerformanceCounterConfiguration = class end
Public Class PerformanceCounterConfiguration

Constructors

Name Description
System_CAPS_pubmethod PerformanceCounterConfiguration()

Initializes a new instance of the PerformanceCounterConfiguration class.

Properties

Name Description
System_CAPS_pubproperty CounterSpecifier

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

System_CAPS_pubproperty SampleRate

Gets or sets the rate at which to sample the performance counter, rounded up to the nearest second.

Methods

Name Description
System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_protmethod Finalize()

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_protmethod MemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethod ToString()

(Inherited from Object.)

Remarks

The PerformanceCounterConfiguration class provides properties to configure a performance counter for a role instance. When you create a PerformanceCounterConfiguration object, you add it to the DataSources collection of a DiagnosticMonitorConfiguration object.

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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Microsoft.WindowsAzure.Diagnostics Namespace

Return to top