How to: Create Performance Counter Categories
You can create a new category to contain custom counters. For example, if you plan to create a series of counters to track various data about the orders processed on your Web site, you might create a category called OrderData on your server and then create the counters you need within it.
Creating a category is not a distinct process from creating the counters that are placed within it; counters can only be created at the point when you create the category itself. You cannot create categories and counters on, or remove them from, remote computers.
There are several ways you can create counters and categories:
You can use the Create method on the PerformanceCounterCategory class to create a new category and simultaneously create a single performance counter within it.
You can create an array of CounterCreationData objects and pass the array as a parameter of the Create methods, creating a set of counters within the category. For more information on this approach, see How to: Create Custom Performance Counters.
You can use the Performance Counter dialog box, opened from Server Explorer, to create multiple counters while simultaneously creating a new category. For more information on this approach, see How to: Create Custom Performance Counters.
Note There are security restrictions that affect your ability to use performance counters. For more information, see Introduction to Monitoring Performance Thresholds.
Note The PerformanceCounter class is not fully supported on Microsoft Windows NT version 4.0. You can read from the system counters, but you cannot create, write to, or delete custom counters.
To create a category and a single counter within it
Call the Create method on the PerformanceCounterCategory class and specify the following parameters:
Parameter Value CategoryName
Any category name that is not already in use on this server.
CategoryHelp
A description of the category.
CounterName
A name for the counter.
CounterHelp
A description of the counter. This text is displayed in Windows Performance Monitor when a user selects a counter and clicks the Explain button.
The following example shows how you might create a simple category with the Create method:
Sub CreateCustomCounter() PerformanceCounterCategory.Create("CategoryName", "CounterHelp", _ PerformanceCounterCategoryType.MultiInstance, _ "CounterName", "CounterHelp") End Sub
void CreateCustomCounter() { PerformanceCounterCategory.Create("CategoryName", "CounterHelp", PerformanceCounterCategoryType.MultiInstance, "CounterName", "CounterHelp"); }
void CreateCustomCounter() { PerformanceCounterCategory.Create("CategoryName", "CounterHelp", PerformanceCounterCategoryType.MultiInstance, "CounterName", "CounterHelp"); }
Note By default, the counters created with this code will be read-write enabled, but your interaction with them via a PerformanceCounter component instance will be read-only unless you specify otherwise. You can change the value of the ReadOnly property for a component instance to false if you want to make modifications to a counter.
See Also
Tasks
How to: Create Custom Performance Counters