Windows System Resource Monitoring

Source: Internet
Author: User
    • 1. Windows comes with System resource monitoring tool
    • 2. Data source for Windows monitoring: Performance Counters
      • 2.1 Performance Counter Architecture
      • 2.2 Performance counter data structure
      • 2.3 Consumption performance counter data
    • 3. Using the PDH-based Python client

1. Windows comes with System resource monitoring tool

As we all know, Windows comes with System Resource Monitor. There are 3 main places:

1) Windows Task Manager Performance tab, including CPU, memory, disk, network and other system resources monitoring. It mainly monitors the overall use of system resources, using it, we can find out whether there are resources to reach the bottleneck and so on.

2) Windows Resource Monitor

This tool can see which processes are consuming the system resources. It allows you to quickly see which processes are taking up your system resources.

3) Performance Monitor

The first two tools already provide most of the features you want to monitor, and in some cases you may still not be able to locate the problem, which requires you to further understand the health of the system. Then this tool is a good choice.

2. Data source for Windows monitoring: Performance Counters

The Windows monitoring tools are able to show these resources, and their data source is a counter called performance.

Docs.microsoft.com/zh-cn/windows/desktop/perfctrs/performance-counters-portal

2.1 PerformanceCounter Architecture

The PerformanceCounter architecture is as follows:

The Producer/consumer architecture is used to support multiple clients consuming data from registry.

, a uses the registry interface to consume data, while B and Performance Monitor two clients use Pdh.dll to consume data.

2.2 Performance Counter data structure

If you want to use the program to consume counter data, regardless of which API you use to consume data, regardless of which tool you use to consume data, you need to understand the domain language of performance counter, that is, to understand how the data inside it is organized.

Its basic concepts are as follows:

Machine: Machines, this is nothing to say, support the consumption of local monitoring data, can also consume other monitoring data. perfobject: Can be understood to monitor what kind of resources, such as processor, disk instance: Monitoring resources may have multiple instances, multiple network cards, multiple CPUs, multiple disks, etc. counter: Counters, Each instance will have multiple counters, such as CPU idle,user,interrupt is a counter


More intuitive understanding of these concepts:

2.3 Consumption performance counter data

From the architecture diagram above, you can consume data in 3 ways, such as Registry API or PDH.dll, or WMI. Both of these APIs are developed in C or C + +.

1) Registry API:

Docs.microsoft.com/zh-cn/windows/desktop/perfctrs/using-the-registry-functions-to-consume-counter-data

2) WMI:

Docs.microsoft.com/zh-cn/windows/desktop/wmisdk/monitoring-performance-data

3) PDH API:

Two versions are currently known:

C++:

Docs.microsoft.com/zh-cn/windows/desktop/perfctrs/using-the-pdh-functions-to-consume-counter-data

Python:

There is a WIN32PDH module in Pywin32, which is the Python version of PDH.

pypi.org/project/pywin32/

Http://timgolden.me.uk/pywin32-docs/win32pdh.html

Other tools:

4) Windows comes with the Typeperf command

5) nsclient++

3. Using the PDH-based Python client

WIN32PDH API Description:

Http://timgolden.me.uk/pywin32-docs/win32pdh.html

A simple tutorial using the WIN32PDH API:

Www.cac.cornell.edu/wiki/index.php?title=Performance_Data_Helper_in_Python_with_win32pdh

A set of APIs based on the WIN32PDH package:

At the far right is the WIN32PDH module, which can be downloaded from the Python repository.

Windows_collector is the core code that I encapsulate to monitor system resources with simple code.

The leftmost is to use this set of APIs. The advantage of using this set of APIs is that you don't have to take the time to learn the WIN32PDH API to easily get the monitoring data you need.

The source code of this set of APIs:

The code naming convention is not python, and it certainly doesn't seem to be much of a problem.

With this set of APIs, you can monitor system resources with simple code, such as:

Objectcollector ("Memory"). Collect ()

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.