服务器性能监控之性能计数器
来源:互联网 发布:深入解析windows 编辑:程序博客网 时间:2024/06/06 18:10
上一篇文章《服务器性能监控之WMI》介绍了通过远程com获取服务器性能(当然也可用于本地),那么这篇主要说说windows系统自带的性能监视功能----->performancecouonter.
打开管理工具-->性能,我们可以立即看到服务器的CPU,进程运行时间,磁盘容量等性能参数走势图。然而不仅仅是这几项,我们可以通过添加技术器来查看其他的性能指标:
如果你说,这么看太麻烦了,OK,我们通过C#将这些值取出来,用于实现自身的性能监视:
1.添加引用:
using System.Diagnostics;
2.创建并实例化PerformanceCounter
public static System.Diagnostics.PerformanceCounter pc= new System.Diagnostics.PerformanceCounter();
public static System.Diagnostics.PerformanceCounter pcm= new System.Diagnostics.PerformanceCounter();
public static System.Diagnostics.PerformanceCounter pcb= new System.Diagnostics.PerformanceCounter();
public static System.Diagnostics.PerformanceCounter pcc= new System.Diagnostics.PerformanceCounter();
//我们用四个对象做不同的操作,注意:是static的,不然每次取出的数据都是初始值,如cpu利用率就是0
public static System.Diagnostics.PerformanceCounter pcm= new System.Diagnostics.PerformanceCounter();
public static System.Diagnostics.PerformanceCounter pcb= new System.Diagnostics.PerformanceCounter();
public static System.Diagnostics.PerformanceCounter pcc= new System.Diagnostics.PerformanceCounter();
//我们用四个对象做不同的操作,注意:是static的,不然每次取出的数据都是初始值,如cpu利用率就是0
3.构造函数
static CapabilityScout()
...{
pc.CategoryName = "Processor";
pc.CounterName = "% Processor Time";
pc.InstanceName = "_Total";
pc.MachineName = ".";
pcm.CategoryName = "Memory";
pcm.CounterName = "% Committed Bytes In Use";
pcm.MachineName = ".";
pcb.CategoryName = "Windows Media Unicast Service";
pcb.CounterName = "Allocated Bandwidth";
pcb.MachineName = ".";
pcc.CategoryName = "Windows Media Unicast Service";
pcc.CounterName = "Connected Clients";
pcc.MachineName = ".";
}
...{
pc.CategoryName = "Processor";
pc.CounterName = "% Processor Time";
pc.InstanceName = "_Total";
pc.MachineName = ".";
pcm.CategoryName = "Memory";
pcm.CounterName = "% Committed Bytes In Use";
pcm.MachineName = ".";
pcb.CategoryName = "Windows Media Unicast Service";
pcb.CounterName = "Allocated Bandwidth";
pcb.MachineName = ".";
pcc.CategoryName = "Windows Media Unicast Service";
pcc.CounterName = "Connected Clients";
pcc.MachineName = ".";
}
4.获取计数器值
获取CPU利用率#region 获取CPU利用率
public static string getCpuUsage()
...{
string used = pc.NextValue().ToString();
return used;
}
#endregion
获取内存使用率#region 获取内存使用率
public static string getMemory()
...{
float used = pcm.NextValue();
return used.ToString();
}
#endregion
获取WMS连接数#region 获取WMS连接数
public static string getConnectedCount()
...{
string count = pcc.NextValue().ToString();
return count;
}
#endregion
获取网络流量#region 获取网络流量
public static string getServerBandWidth()
...{
string bandwidth = pcb.NextValue().ToString();
return bandwidth;
}
#endregion
当然,这里只是其中及少的部分,不过通过使用同样的方式,我们可以获取更多的性能以及进程运行的情况,但是要说明的一点是,所获取的数据必定是windows服务所提供的,当然我们也可以自己写一些windows服务,添加到系统performancecounter中来,对.net来说也是非常方便的。
怎么样,和WMI比起来,是不是又方便了一些呢,呵呵~~
- 服务器性能监控之性能计数器
- 服务器性能监控之性能计数器
- 使用WMI和性能计数器监控远程服务器权限设置
- 服务器性能监控之WMI
- 服务器性能监控之WMI
- 服务器性能监控之WMI
- 常用 监控SQLSERVER性能计数器
- 常用 监控SQLSERVER性能计数器
- 使用性能计数器监控应用程序
- 常用 监控SQLSERVER性能计数器
- 性能监控-Windows计数器配置
- 性能计数器之CPU
- 性能计数器之CPU
- 性能计数器之CPU
- SQL SERVER资源性能监控-性能计数器监控点
- linux服务器历险之linux性能监控
- linux服务器历险之linux性能监控
- linux服务器历险之linux性能监控
- Display Tag使用小记
- PHP ADODB 1.99版手册中文翻译
- ASP.NET保持用户状态的九种选择
- 让div自动适应内容的高度
- 找到一篇关键文档 - cache user guide
- 服务器性能监控之性能计数器
- 进程间的通讯实现(IPC)的11种方法
- 影视关键字
- 复杂ASP.NET服务器控件调整小技巧
- ASP.NET 格式化字符串
- Windows API一日一练(20)LoadString、LoadIcon和LoadCursor函数
- java.lang.SecurityException: Prohibited package name: java.edu.ynu.app
- 走向J2EE,漫长的道路(转载)
- ICEfaces Note(1)