写了个在线的性能计数器,希望对大家有用

    这两天在研究测试,顺手写了个在线的性能计数器。使用ZedGraph控件做为展示,并配合Asp.net Ajax的UpdatePanel和Timer控件实现定时无刷新。

   System.Diagnostics命名空间里提供了与NT性能计数器相关的类,使用性能计数器提取数据,然后再使用ZedGraph控件来展示数据,最终的效果如下:
写了个在线的性能计数器,希望对大家有用

 

添加计数器界面:
写了个在线的性能计数器,希望对大家有用
1、获取计数器类别:

写了个在线的性能计数器,希望对大家有用PerformanceCounterCategory[] catalogs = PerformanceCounterCategory.GetCategories(); 

2、获取某个分类下的计数器,并且排序:

 

写了个在线的性能计数器,希望对大家有用        PerformanceCounterCategory category = new PerformanceCounterCategory(categoryName);
写了个在线的性能计数器,希望对大家有用
写了个在线的性能计数器,希望对大家有用        
string[] instances = category.GetInstanceNames();
写了个在线的性能计数器,希望对大家有用        PerformanceCounter[] counters 
= null;
写了个在线的性能计数器,希望对大家有用
写了个在线的性能计数器,希望对大家有用        
//判断是否有实例
写了个在线的性能计数器,希望对大家有用
        if (instances != null &&
写了个在线的性能计数器,希望对大家有用            instances.Length 
> 0)
        }

3、添加计数器到统计

使用一个类来保存计数器信息。

写了个在线的性能计数器,希望对大家有用    [Serializable]
写了个在线的性能计数器,希望对大家有用    
private class CounterInfo
    }

将计数器信息添加到SortedList对象中:  

写了个在线的性能计数器,希望对大家有用        SortedList<string, CounterInfo> list = this.Counters;
写了个在线的性能计数器,希望对大家有用
写了个在线的性能计数器,希望对大家有用        
string strInstance = "";
写了个在线的性能计数器,希望对大家有用        
if (this.lbInstance.Items.Count > 0)
        }

4、ZedGraph控件展现计数器值:

写了个在线的性能计数器,希望对大家有用        //这里不能使用ViewState
写了个在线的性能计数器,希望对大家有用
        Dictionary<string, PointPairList> dic = Cache["datasource"as Dictionary<string,PointPairList>;
写了个在线的性能计数器,希望对大家有用        
if (dic == null)
 dic;

本来是做了个演示的在http://www.massany.com/perfmon.aspx,但是服务器那边出于安全考虑,运行不了,只有大家自己下载了运行了。

工程下载:http://www.massany.com/perfmon.zip


相关文章:

  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-12-12
  • 2021-05-17
  • 2022-12-23
  • 2021-08-17
猜你喜欢
  • 2022-01-02
  • 2021-12-12
  • 2021-06-27
  • 2021-10-31
  • 2021-05-31
  • 2021-08-29
  • 2022-12-23
相关资源
相似解决方案