Collecting Performance Counter Data

Retired Content

This content and the technology described is outdated and is no longer being maintained. For more information, see Transient Fault Handling.

patterns & practices Developer Center

Reactive rules can use performance counter data from roles as part of the rule definition. For example, a rule may monitor the CPU utilization of a role to determine whether the block should scale a target. The block reads performance counter data from the Microsoft Azure Diagnostics table named WADPerformanceCountersTable in Azure storage.

By default, Azure does not write performance counter data to the Azure Diagnostics table in Azure storage. Therefore, you should modify the roles from which you need to collect performance counter data to save the data.

Note

The role must be running in full trust mode to be allowed to write performance monitoring data to the Azure Diagnostics table.

The following code sample shows how you can modify a web role to write CPU usage performance data to storage. In this example, the web role samples the percent processor time usage performance counter every 30 seconds, and writes the performance data to Azure Diagnostics table storage every minute.

using System;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;

public class WebRole : RoleEntryPoint
{
    public override bool OnStart()
    {
        var config = DiagnosticMonitor.GetDefaultInitialConfiguration();

        var cloudStorageAccount =
            CloudStorageAccount.Parse(
              RoleEnvironment.GetConfigurationSettingValue(
              "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));

        // Get the perf counters
        config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

        // Add the perf counters
        config.PerformanceCounters.DataSources.Add(
            new PerformanceCounterConfiguration
            {
                CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                SampleRate = TimeSpan.FromSeconds(30)
            });

        DiagnosticMonitor diagMonitor = DiagnosticMonitor.Start(cloudStorageAccount, config);

        return base.OnStart();
    }
}

For more information, see "Overview of Creating and Using Performance Counters in a Microsoft Azure Application" on MSDN.

Next Topic | Previous Topic | Home

Last built: June 7, 2012