The previous article, "WMI for server Performance monitoring", describes how to get server performance through remote COM (which can also be used locally), so this article mainly says that the Windows system comes with performance monitoring----->performancecouonter.
Open management Tools--performance, we can immediately see the server's CPU, process run time, disk capacity and other performance parameters chart. However, more than just these, we can look at other performance metrics by adding a technical device:
If you say it's too much trouble, OK, we'll take these values out of C # to implement our own performance monitoring:
1. Add a reference:
Using System.Diagnostics;
2. Create and Instantiate PerformanceCounter
public static System.Diagnostics.PerformanceCounter pc= new System.Diagnostics.PerformanceCounter ();p ublic static System.Diagnostics.PerformanceCounter pcm= New System.Diagnostics.PerformanceCounter ();p ublic static System.Diagnostics.PerformanceCounter pcb= New System.Diagnostics.PerformanceCounter ();p ublic static System.Diagnostics.PerformanceCounter pcc= new System.Diagnostics.PerformanceCounter ();//We use four objects to do different things, Note: It is static, otherwise the data taken each time is the initial value, such as CPU utilization is 0
3. Constructors
Static Capabilityscout () ... {PC. CategoryName = "Processor";p C. CounterName = "% Processor time";p c. INSTANCENAME = "_total";p C. MachineName = "."; Pcm. CategoryName = "Memory";p cm. CounterName = "% Committed Bytes in use";p cm. MachineName = "."; Pcb. CategoryName = "Windows Media Unicast Service";p CB. CounterName = "Allocated Bandwidth";p CB. MachineName = "."; Pcc. CategoryName = "Windows Media Unicast Service";p cc. CounterName = "Connected clients";p cc. MachineName = ".";}
4. Get Counter Value
Get CPU Utilization #region Get CPU utilization public static string Getcpuusage () ... { string used = pc. NextValue (). ToString (); return used; } #endregion Get memory usage #region get memory usage public static string GetMemory () ... { float used = PCM. NextValue (); return used. ToString (); } #endregion get WMS Connections #region Get the number of WMS connections public static string Getconnectedcount () ... { string count = PCC. NextValue (). ToString (); return count; } #endregion Get network traffic #region get network traffic public static string Getserverbandwidth () ... { String bandwidth = PCB. NextValue (). ToString (); return bandwidth; } #endregion
Of course, this is only a few of them, but by using the same approach, we can get more performance and run the process, but the point is that the data obtained must be provided by the Windows service, and of course we can write some Windows services ourselves. Added to the system PerformanceCounter, which is also very convenient for. Net.
How, compared with WMI, is not a little more convenient, hehe ~ ~