Windows performance monitor Overview
Windows performance monitor is a Microsoft Management Console (MMC) management unit that provides tools for analyzing system performance. Monitors applications in real time only from a single consoleProgramAnd hardware performance, custom data to be collected in logs, define thresholds for alarms and automatic operations, generate reports, and view performance data in various ways.
Start Windows Performance Monitor: start --> Run-> enter perfmon --> press ENTER
Add-save counter settings:
In Windows 2003, after adding a counter, press Ctrl + S to save the settings as a file, so that you can view the settings directly next time. In Windows, the settings are not so straightforward.
Start --> Run --> enter MMC --> file --> Add/delete a management unit --> select performance monitor --> Add, and then add your counter in performance (local, in this way, you can save it for future viewing.
Run:
Common monitoring counters:
Object |
Counter |
Description |
. Net CLR exceptions |
# Of exceps thrown/sec |
Displays the number of exceptions thrown per second. This includes. Net exceptions and unmanaged exceptions that convert to. Net exceptions. Performance decreases as the number increases. |
. Net CLR memory |
# Bytes in all heaps |
Display the total size of the other four counters: Gen 0 heap size, Gen 1 heap size, Gen 2 heap size, and large object heap size. This counter indicates the memory allocated on the GC stack (in bytes ). The value of this counter is always smaller than the value of Process \ private bytes. Process \ private bytes counts the mem_commit area of the process. Private bytes minus # bytes in all heaps is the number of bytes submitted by the unmanaged object. It is used to monitor possible memory leaks, or to monitor whether the memory usage of managed or unmanaged objects is too high. |
. Net CLR remoting |
Remote CILS/sec |
Displays the number of remote process calls per second. A Remote Procedure Call is a call to any object outside the application domain where the caller is located. This counter is not an average value over a period of time; it shows the result of dividing the difference between the observed values of the last two samples by the sampling interval. |
. NET data provider for Oracle |
Numberoffreeconnections |
The number of available connections in the connection pool. |
. NET data provider for sqlserver |
Numberoffreeconnections |
The number of available connections in the connection pool. |
Process |
% Processor time |
Display the CPU time used by all process threads to execute commandsPercentage. Commands are the basic execution units in the computer, threads are the objects for executing commands, and processes are the objects created when running programs. This count contains information that is executed when processing certain hardware interruptions and trap conditions.Code. If the total processor time is long, use this counter to identify the process that causes high CPU utilization. |
Process |
Handle count |
Displays the total number of opened handles of this process. This number is the total number of handles currently opened by each thread in this process. The increase in the handle count in a specific process may be a symptom of a handle leakage error process, which may cause performance problems on the server. This problem may not occur, but it is very important to monitor it for a period of time to determine whether a handle leakage occurs. |
Process |
Thread Count |
Number of active threads in the process. A command is a basic execution unit in a processor, and a thread is the object that executes the command. Each running process has at least one thread. |
Sqlserver: General Statistics |
User connections |
Displays the current number of sqlserver connections, not the number of users. If the counter exceeds 255, you need to set the "Maximum worker threads" configuration value of sqlserver to 255 higher than the default value. If the number of connections exceeds the number of available threads, sqlserver will share the thread, which will affect the performance. "Maximum worker threads" needs to be set to be higher than the maximum number of connections that your server has ever reached. |
Sqlserver: locks |
Number of deadlocks/sec |
The number of deadlocks per second. deadlocks are harmful to application scalability and lead to poor user experience. The counter value must be 0. |
Logicaldisk |
% Free space |
% Free space is the total available space on the selected Logical Disk DrivePercentage. |
Physicaldisk |
Disk Read Bytes/sec |
The speed at which bytes are transferred from the disk during the read operation. |
Physicaldisk |
Disk write Bytes/sec |
The Byte speed transmitted to the disk during write operations. |
By default, the following two counters are switched off. You need to configure % WinDir % \ microsoft.net \ framework64 \ v2.0.50727 \ config \ machine. the path of the 32-bit and 64-bit operating systems is also different. Otherwise, the data cannot be collected.
. NET data provider for Oracle |
Numberoffreeconnections |
. NET data provider for sqlserver |
Numberoffreeconnections |
Add configuration and restart the corresponding process (restart the service, or restart IIS, etc)
system. diagnostics
switches
Add name = "connectionpoolperformancecounterdetail" value = "4" />
switches
system. diagnostics
Use C # To collect counter data:
Although Windows comes with the perfmon tool and can generate reports and view performance data in various ways, sometimes we still define some of our own curves or reports, then we need to collect the Performance Monitor Data. C # provides the performancecountercategory (performance object) and performancecounter (performance counter component) classes, and provides some methods for operating the Performance Monitor, in this way, we can read and save the data to the database or files, and use it to generate curves, reports, or alarm mail at will...
Sample Code:
Using System;
Using System. diagnostics;
Using System. Threading;
Namespace Testapplication
{
Public Class Program
{
Static Void Main ( String [] ARGs)
{
Console. writeline (getperfcount ( "Process" ,"% Processor time" , "_ Total" ));
Console. writeline (getperfcount ( ". Net CLR memory" , "# Bytes in all heaps" , "_ Global _" ));
Console. writeline (getperfcount ( "Sqlserver: General Statistics" , "User connections" ));
Console. Read ();
}
/// <Summary>
/// Obtain the counter sample and return the calculated value for it-counters with instances (for most counters)
/// </Summary>
/// <Param name = "categoryname"> </param>
/// <Param name = "countername"> </param>
/// <Param name = "instance"> </param>
/// <Returns> </returns>
Public Static Float Getperfcount ( String Categoryname, String Countername, String Instance)
{
Performancecounter counter = New Performancecounter
{
Categoryname = categoryname,
Countername = countername,
InstanceName = instance,
Machinename = "." ,
Readonly = True
};
Counter. nextvalue ();
Thread. Sleep (200 );
Try
{
If (Counter! = Null )
{
Return Counter. nextvalue ();
}
}
Catch (Exception)
{
Return -2f;
}
Return -1f;
}
/// <Summary>
/// Obtain the counter sample and return the calculated value for it -- a counter without an instance
/// For example, categoryname = sqlserver: General Statistics, countername = user connections
/// </Summary>
/// <Param name = "categoryname"> </param>
/// <Param name = "countername"> </param>
/// <Returns> </returns>
Public Static Float Getperfcount ( String Categoryname, String Countername)
{
Performancecounter counter = New Performancecounter
{
Categoryname = categoryname,
Countername = countername
};
Counter. nextvalue ();
Thread. Sleep (200 );
Try
{
If (Counter! = Null )
{
Return Counter. nextvalue ();
}
}
Catch (Exception)
{
Return -2f;
}
Return -1f;
}
}
}