Monitor with Windows performance counters (PerformanceCounter)

Source: Internet
Author: User

I. Overview

Performance monitoring, which is a system feature provided by Windows NT. Windows NT has always been integrated with performance monitoring tools that provide information about the current health of the operating system and provide hundreds of performance counters for a variety of objects. Performance object, is the object to be monitored, typical examples are processor, Process, Memory, tcp/udp/ip/icmp, PhysicalDisk and so on. Counters typically provide performance-related information about the operating system, applications, services, drivers, and so on to analyze system bottlenecks and diagnose and tune system and application performance. The performance counter mechanism enables applications and operating system components to report performance-related statistics to performance monitoring applications such as Performance Monitor (Performance Monitor). You can view performance objects, performance counters, and object instances in PerfMon.exe by adding counters to view related descriptive information.

In fact, you can write programs to access all of the Windows performance counters. In Windows, the registry is a mechanism for accessing performance counters. Performance information does not actually exist in the registry and is not viewable in Registry Editor RegEdit.exe, but can be accessed through registry functions, using registry keys to obtain data from the performance data provider. Open a special key named Hkey_performance_data and use the RegQueryValueEx function to query the value below the key to directly access the registry performance counter information. Of course, performance counter information can also be accessed using the Performance Data Helper (PDH, Performance Data Helper) API (Pdh.dll).

Performance Logs and Alerts are a Management performance monitoring tool that is released as part of the Windows operating system. It relies on performance counters published by various Windows components, subsystems, and applications, allowing you to track resource usage and draw them graphically for time. You can use Performance Logs and Alerts to monitor standard performance counters (for example, memory usage or processor usage), or you can define your own custom counters to monitor application-specific activities.

II. Hkey_performance_data Data Organization

The head of the performance data is a Perf_data_block structure (1) that describes the overall information about the system and performance data, which can be queried from the global key value. After Perf_data_block, the entire performance object type (Perf_object_type) in the system is defined, where the offset of the next performance object type is described in the header of each object type.

Fig. 1 Fig. 2

There are two types of performance objects: One is a single-instance object and the other is a multi-instance object. Figure 2 and Figure 3 describe how the data is organized for both performance objects, respectively. Each object data block contains a PERF_OBJECT_TYPE structure that describes the performance data of the object. followed by a list of perf_counter_definition structures that describe all the counter definitions for the performance object. For a single-instance object, the counter definition list is followed by a perf_counter_block structure, followed by the counter data. The offset of the counter data relative to the perf_counter_block is defined in each perf_counter_definition structure, so the value of all counters can be easily obtained. For multi-instance performance objects, the perf_counter_definition structure list is followed by a set of instance information data blocks, each representing an object instance. Each instance information data block consists of a perf_instance_definition struct, an instance name, and a perf_counter_block struct body. The counter value data is followed by the same as the single-instance object.

Figure 3

Third, the performance counter architecture

Performance counters are based on the client server structure, where performance data is stored in shared memory, custom performance counters are used in the application, and performance counters are counted when the application is called. The architecture is as follows:

Performance counters can get real-time measurement data for application performance without having to log in to do additional processing. and performance counters can be viewed remotely and managed by the Administrative Tools (MOM). It's also very small in loss.

Four. NET performance counter implementation

There is an assembly under the. NET Framework

(C:windowsmicrosoft.netframeworkv2.0.50727perfcounter.dll) Implements performance counter functions, including the installation/uninstallation of performance counters, and the reading and writing of values.

The namespace System.diagnostic provides a set of performance counter classes, including Performancecountercategory,performancecounter,performancecounterinstaller,coutersampl E and so on.

performance counters in. NET are well-encapsulated in abstraction and are much easier to implement than C + +. We often focus only on data metrics for some request types, such as the following:

Requests Started

Requests executing

Requests completed

Requests Failed

Request Execution Time

Requests/hour

Requests/5min

Requests/min

Requests/sec

But the real need to do these performance counters to install/unload, count, read or need a lot of code, through encapsulation to simplify the programming interface. For services implemented using WCF, further encapsulation can be done based on the extensibility of WCF.

Monitor with Windows performance counters (PerformanceCounter)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.