windows性能监视功能
来源:互联网 发布:莆田淘宝美工培训 编辑:程序博客网 时间:2024/05/22 00:34
这篇主要说说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.获取计数器值
#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
#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来说也是非常方便的。
- windows性能监视功能
- 如何监视 WINDOWS 的性能
- nmon 工具 Linux 提供监视和分析性能数据功能
- WINDOWS服务器性能监控器的监视以及邮件预警配置
- 服务器性能监视:性能监视工具
- 使用 WMI 监视性能
- 监视服务器性能
- 性能监视类
- Linux性能监视
- ubuntu系统性能监视
- appfabric 性能监视篇
- RMAN性能和监视
- VS2010性能监视工具
- perf_event_open 设置性能监视
- 性能测试,监视
- JMeter 服务器性能监视
- 性能监视工具
- 用Windows窃听器监视
- 在Ubuntu上为Android系统内置C可执行程序测试Linux内核驱动程序
- 使用PhoneGap制作基于HTML5的跨平台应用和游戏1 – PhoneGap简介
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 桌面添加数据库链接测试test.udl后缀为udl即可
- 在Ubuntu为Android硬件抽象层(HAL)模块编写JNI方法提供Java访问硬件服务接口
- windows性能监视功能
- 嵌入式sql的示例
- IOS OOP(面向对象编程)基础-间接的使用
- 编译多线程应用程序 调试多线程程序
- Linux/Ubuntu下C语言开发PHP的.so扩展模块过程
- vb.net ---- n*n随机矩阵转换
- 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务
- javascript Throw
- 诠释的伤感独特个性日志发布:你是今生最让我伤心的人