Performance counters are Windows's way of collecting performance data from running processes. Windows organizes performance counters into categories. Each category defines a specific set of performance counters. For example, there are categories such as Memory, Processor, and PhysicalDisk; the Memory category has various counters, such as Available Bytes, Cache Bytes, and Committed Bytes. Some categories are further divided into instances. For example, the Process category is divided into several instances, each representing a running process on the computer. A new instance is added to the category whenever a new process is started, and the instance is removed when a process is killed. Each instance can have performance counters (such as I/O Read Bytes/sec) that specify the memory activity of a process. Usually all the instances in a category have the same list of performance counters. Of course, each of the performance counters has unique performance data associated with it. The PerformanceCounter class enables you to read performance samples for processes that are running on a machine. By using this class, an application can even publish its own performance counter to inform the world about its performance level. Table 10.7 lists some important members of the PerformanceCounter class. Table 10.7. Important Members of the PerformanceCounter ClassMember | Type | Description |
---|
CategoryName | Property | Specifies the performance counter category name. | Close() | Method | Closes the performance counter and frees all the resources. | CounterHelp | Property | Specifies the performance counter description. | CounterName | Property | Specifies the performance counter name. | CounterType | Property | Specifies the performance counter type. | Decrement() | Method | Decrements the performance counter value by one. | Increment() | Method | Increments the performance counter value by one. | IncrementBy() | Method | Increments or decrements the performance counter value by a specified amount. | InstanceName | Property | Specifies the instance name. | MachineName | Property | Specifies the computer name. | NextSample() | Method | Returns an object of type CounterSample that has properties such as RawValue, BaseValue, TimeStamp, and SystemFrequency. These properties provide you with detailed information on the performance data. | NextValue() | Method | Retrieves the current calculated value (a float type) for a performance counter. | RawValue | Property | Retrieves the raw, or uncalculated, value for a performance counter. | ReadOnly | Property | Indicates whether the PerformanceCounter object is in read-only mode. | RemoveInstance() | Method | Deletes an instance from the PerformanceCounter object. | The .NET Framework allows applications to create custom performance counters and publish their performance data. This performance data can then be monitored via the Performance Monitoring tool (perfmon.exe). Visual Studio .NET makes it easy for you to create new performance categories and counters: It provides the Performance Counter Builder Wizard, which is available via Server Explorer. Open Server Explorer and, from the Servers node, select the server in which you want to create a performance counter. Right-click the Performance Counters node and select the Create New Category option. The Performance Counter Builder dialog box appears. Enter the values in the dialog box and then click OK to create the category and the counter. |