PerformanceCounterConfiguration Class
Assembly: Microsoft.WindowsAzure.Diagnostics (in Microsoft.WindowsAzure.Diagnostics.dll)
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 a role’s OnStart() method. This method creates a new PerformanceCounterConfiguration object, specifies the performance counter and sample rate, adds the configuration to our DiagnosticMonitorConfiguration object, and starts the DiagnosticMonitor.
public override bool OnStart()
{
// Get the default initial configuration for DiagnosticMonitor.
DiagnosticMonitorConfiguration diagnosticConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
// Use 30 seconds for the performance counter sample rate.
TimeSpan perfSampleRate = TimeSpan.FromSeconds(30.0);
// Add a performance counter for processor time.
diagnosticConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
{
CounterSpecifier = @"\Processor(_Total)\% Processor Time",
SampleRate = perfSampleRate
});
// Add a performance counter for available memory.
diagnosticConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
{
CounterSpecifier = @"\Memory\Available Bytes",
SampleRate = perfSampleRate
});
// Schedule a transfer period of 30 minutes.
diagnosticConfiguration.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(30.0);
// Start the DiagnosticMonitor using the diagnosticConfig and our connection string.
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfiguration);
return base.OnStart();
}
Development Platforms
Windows Vista, Windows 7 and Windows Server 2008Target Platforms