写了个在线的性能计数器,希望对大家有用
写了个在线的性能计数器,希望对大家有用
这两天在研究测试,顺手写了个在线的性能计数器。使用ZedGraph控件做为展示,并配合Asp.net Ajax的UpdatePanel和Timer控件实现定时无刷新。
System.Diagnostics命名空间里提供了与NT性能计数器相关的类,使用性能计数器提取数据,然后再使用ZedGraph控件来展示数据,最终的效果如下:
添加计数器界面:
1、获取计数器类别:
2、获取某个分类下的计数器,并且排序:
string[] instances = category.GetInstanceNames();
PerformanceCounter[] counters = null;
//判断是否有实例
if (instances != null &&
instances.Length > 0)
{
SortedList list = new SortedList();
foreach (string ins in instances)
{
list.Add(ins, ins);
}
this.lbInstance.DataSource = list;
this.lbInstance.DataBind();
this.lbInstance.SelectedIndex = 0;
counters = category.GetCounters(instances[0]);
}
else
{
counters = category.GetCounters();
}
SortedList listCounter = new SortedList();
foreach (PerformanceCounter c in counters)
{
listCounter.Add(c.CounterName, c.CounterName);
}
3、添加计数器到统计
使用一个类来保存计数器信息。
private class CounterInfo
{
public string CategoryName;
public string CounterName;
public string InstanceNames;
public CounterInfo(string categoryName, string counterName, string instanceNames)
{
CategoryName = categoryName;
CounterName = counterName;
InstanceNames = instanceNames;
}
}
将计数器信息添加到SortedList对象中:
string strInstance = "";
if (this.lbInstance.Items.Count > 0)
{
bool bFlag = true;
foreach (ListItem item in this.lbInstance.Items)
{
if (item.Selected)
{
if (bFlag)
{
strInstance = item.Value;
bFlag = false;
}
else
{
strInstance += "," + item.Value;
}
}
}
}
foreach(ListItem item in this.lbCounter.Items)
{
if (item.Selected)
{
list[this.ddlCategory.SelectedValue + " " + item.Value + " " + strInstance] = new CounterInfo(this.ddlCategory.SelectedValue,item.Value,strInstance);
}
}
4、ZedGraph控件展现计数器值:
Dictionary<string, PointPairList> dic = Cache["datasource"] as Dictionary<string,PointPairList>;
if (dic == null)
{
dic = new Dictionary<string, PointPairList>();
}
ArrayList labels = new ArrayList();
foreach (CounterInfo ci in this.Counters.Values)
{
PerformanceCounter counter = null;
if (string.IsNullOrEmpty(ci.InstanceNames))
{
PointPairList list = null;
dic.TryGetValue(ci.CategoryName + " " + ci.CounterName, out list);
if (list == null)
{
list = new PointPairList();
}
counter = new PerformanceCounter(ci.CategoryName, ci.CounterName);
list.Add(list.Count + 1, counter.NextValue());
dic[ci.CategoryName + " " + ci.CounterName] = list;
labels.Add(ci.CategoryName + " " + ci.CounterName);
}
else
{
foreach (string ins in ci.InstanceNames.Split(','))
{
PointPairList list = null;
if (!dic.TryGetValue(ci.CategoryName + " " + ci.CounterName + " " + ins,out list))
{
list = new PointPairList();
}
counter = new PerformanceCounter(ci.CategoryName, ci.CounterName,ins);
list.Add(list.Count + 1, counter.NextValue());
dic[ci.CategoryName + " " + ci.CounterName + " " + ins] = list;
labels.Add(ci.CategoryName + " " + ci.CounterName + " " + ins);
}
}
}
//生成随机颜色
Random random = new Random(128);
for (int i = 0; i < labels.Count; i++)
{
pane[0].AddCurve(labels[i] as string, dic[labels[i] as string], Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)));
}
pane.AxisChange(g);
Cache["datasource"] = dic;
本来是做了个演示的在http://www.massany.com/perfmon.aspx,但是服务器那边出于安全考虑,运行不了,只有大家自己下载了运行了。
工程下载:http://www.massany.com/perfmon.zip
转载于:https://www.cnblogs.com/jinyong/archive/2007/04/08/704921.html
写了个在线的性能计数器,希望对大家有用相关推荐
- springboot md5加密_实在!基于Springboot和WebScoket,写了一个在线聊天小程序
基于Springboot和WebScoket写的一个在线聊天小程序 (好几天没有写东西了,也没有去练手了,就看了看这个...) 项目说明 此项目为一个聊天的小demo,采用springboot+web ...
- 专科python应届生工资多少-应届毕业生自述面试15K月薪的Python后端开发经历,希望对你有用...
原标题:应届毕业生自述面试15K月薪的Python后端开发经历,希望对你有用 前言 马上就要到十二月,2018年也即将过去,众所周知每年的三四月份都是招聘高峰期,俗称:"金三银四" ...
- 高斯伪谱法 matlab,Gauss 高斯伪谱法求解的 ,希望对大家有用的!代码比较复杂,但是可以运行。 matlab 263万源代码下载- www.pudn.com...
文件名称: Gauss下载 收藏√ [ 5 4 3 2 1 ] 开发工具: Windows_Unix 文件大小: 273 KB 上传时间: 2016-08-12 下载次数: 0 提 供 者 ...
- 近期新作品:醉眼看 ORACLE 和SAP ERP,希望对大家有用
近期新作品:"醉眼"看 ORACLE 和SAP ERP,希望对大家有用[@more@]前言: 作为由数据库起家的企业应用"后起之秀"的ORACLE 公司在企业的 ...
- 写了一个在线流程设计器,效果很炫[Siverlight版本]
组件描述 让流程配置不在繁琐死板,UI界面效果极炫,设计流程图(工作流)就像使用Office Visio,所见即所得,让您以及您的客户眼前为之一亮,要想看到在线DEMO,下载Siverlight 3以 ...
- 女朋友生日java程序_★★女朋友要过生日了!我想用java为她写一个程序,一举两得啊! 希望大家多提建议啊!谢谢!!!...
女朋友要过生日了,我想用java为她写一个程序,所以想请教大家, 希望大家给我出出点子, 同时手头有3D 等漂亮图形的java程序或其他一些特效的文字,图形java程序,都希望大家多提供, 多帮 ...
- F28379D烧写双核程序(在线离线)
F28379D烧写双核程序(在线&离线) 文章信息 开发环境 烧写双核程序前需知 1. 在线 1.1 编译烧写CPU1程序到F28379D中 1.2 编译CPU2程序,把生成的``.out`` ...
- 在线运行php画图,PHP 写的代码在线运行工具
由于权限问题,编译 c 语言要 root 权限,这名改成你自己的root密码 echo 'root' | sudo /** author:zbseoag 仅限于本地使用,不要放在服务器上 因为没 ...
- python写炒股软件_在线配资,【原创】用python开发股票自动技术分析的软件(
一.准备一个沪深股市的股票代码和简称的对照表,存在csv文件或者txt文件中. 二.读取这个文件,循环将所有股票的历史数据都下载到本地,保存为名字为股票代码的csv文件. 三.逐个读取所有这些csv文 ...
最新文章
- linux系统内存执行elf的多种方式
- ldd查看可执行程序的依赖库
- 卷积神经网络(二):卷积神经网络CNN的BP算法
- FGPA异步信号问题
- 模拟登录123026网站
- 前端学习(649):编译和解释性语言的区别
- Dubbo项目简单实践
- java anotherstring_徐葳【2019版最新】40小时掌握Java语言之06String类
- Helm 3 完整教程(十七):Helm 流控制结构(1)if / else 语句
- windos 服务怎么写_我的产品或服务怎么写?
- 【Nokov】动作捕捉系统标定与机械臂各坐标系的说明
- 常用的织梦(dedecms)调用标签
- Mosek学习笔记2:优化
- word转html,word转pdf
- 软件测试肖sir___项目讲解之银行项目
- 【产品】电池容量简介
- python 英语词频统计_Python实现统计英文文章词频的方法分析
- A - 可以教学姐画画嘛QAQ
- 脑裂问题以及如何避免
- win10 linux 修复引导菜单,win10 + Ubuntu16.04双系统修复linux grub引导丢失