Installing Performance Counters

here i talked about instrumenting your applications with Windows Performance Counters. A number of people asked me how to install such a counter during deployment.

The easiest way is to derive from a class called PerformanceCounterInstaller, set the appropriate properties and run it (from an admin priv account) with installutil.exe. The System.Diagnostics namespace also provides APIs to manually create and remove counters. Here is a sample how to install the two counters I used in my previous article.

using System;

using System.Diagnostics;
using System.ComponentModel;

 

namespace PerfCounterInstaller

{

  [RunInstaller(true)]

  public class MyInstaller : PerformanceCounterInstaller

  {

    public MyInstaller()

    {

      this.CategoryName = “SuspiciousActivity”;

 

      CounterCreationData ccd1 = new CounterCreationData(

        “ValidationErrorsTotal”,

        “Total Numbers of Validation Errors”,

        PerformanceCounterType.NumberOfItems32);

 

       CounterCreationData ccd2 = new CounterCreationData(

         “ValidationErrorsPerSecond”,

         “Validation Errors per Second”,

         PerformanceCounterType.RateOfCountsPerSecond32);

 

       Counters.Add(ccd1);

       Counters.Add(ccd2);

     }

   }

}

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s