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);
}
}
}
