This project is read-only.


The Windows Azure Custom Performance Counters project is a startup task that facilitates implementing custom performance counters in web and worker roles.

Using custom performance counters is a very good technique to monitor your applications and understand if they are behaving correctly. However, using custom performance counters in Windows Azure Web or Worker Roles can be a challenge.

The Windows Azure Custom Performance Counters project focuses on making it easier to use custom performance counters in Web or Worker Roles. Instead of creating custom code to handle performance counter creation, this project is a startup task you can execute from your role which accepts performance counter information through command line parameters.


How to build

The environment used to create this project is the following:

  • Windows 8.1
  • Visual Studio 2013
  • Windows Azure SDK v2.2

Although the project uses the most recent technology and product versions, it does not rely on any special feature so, in theory, it is possible to run and compile it using older versions of Windows, Visual Studio and Windows Azure SDK. We just did not have time to test it!

The project also uses the following components you may need to install:


Usage guide

After compiling the solution, you need to copy the CreatePerformanceCounters.exe file to your project folder. After that, add it as an existing item to your project:


Make sure you change the file property Copy to Output Directory to Copy Always. You can do that by right clicking on the CreatePerformanceCounters.exe file and then selecting Properties on the context menu.


The next step would be creating a startup task to call the CreatePerformanceCounters tool. Since there already is plenty of content regarding this topic on the internet, like Run Startup Tasks in Windows Azure from MSDN, here is the summarized procedure:

Add a batch script to your role project, like CreatePerfCounters.bat or CreatePerfCounters.cmd. Remember to change its Copy to Output Directory property to Copy always.

Change the file ServiceDefinition.csdef by adding the Startup Task inside your role tag, similar to:

<ServiceDefinition …>
    <WebRole …>
            <Task commandLine="CreatePerfCounters.cmd" executionContext="elevated" taskType="simple" />

Now you need to add code to your batch file to call the CreatePerformanceCounters tool, using the following syntax: CreatePerformanceCounters.exe /C <PerformanceCounterInformation>

Where /C indicates you want to create the counters and the <PerformanceCounteInformation> parameter needs to have the following JSON format (linebreaks and tabulation were added to increase understanding):


Just remember that {} indicates a collection in JSON, so you may add multiple categories and inside them multiple counters as well.

The CategoryType needs to have a numeric value from the System.Diagnostics.PerformanceCounterCategoryType enum and the CounterType needs to have a numeric value from the System.Diagnostics.PerformanceCounterType enum.

Besides the /C parameter, some other parameters are also supported:

  • /H: Displays help
  • /V <PerformanceCounterInformation>: Validates <PerformanceCounterInfomation> syntax.


Collecting Custom Performance Counters

Now that your project is created, you can use Windows Azure Diagnostics to collect your custom performance counters. If you use Visual Studio 2013 and Windows Azure SDK v2.2 An easy way to achieve this is following the steps below:

Right click on your role and select Properties…


On the Configuration section, select Custom plan and then click on the Edit… button


On the Diagnostics configuration window, select the Performance counters tab, inform your performance counter information and click the Add button. Also, remember to change the Transfer period (min), indicating how often the data will be transferred to a Windows Azure Storage account.


After adding the counter, you can also define the Sample rate (sec) to inform Windows Azure Diagnostics how often the counter should be collected.


Showing Custom Performance Counters on Management Portal

Once you deploy your project on Windows Azure, it is possible to analyze custom performance counter date on the management portal.

First, on the Configure section from your Cloud Services you need to change the Monitoring Level from Minimal to Verbose.


After saving and waiting for the configuration to be applied, you can add your custom performance counters using the Add Metrics option on the Monitor section.


The screenshot below shows some custom performance counters under monitoring on the management portal.


Last edited Dec 30, 2013 at 3:09 PM by rafaelgodinho, version 3