用程序来自定义Performance Counter
To create a new category and set of performance counters programmatically:
代码
// Create a collection of type CounterCreationData
var collection = new CounterCreationDataCollection();
// Create the counter and set its properties.
var data = new CounterCreationData("Number Of Items", "...", PerformanceCounterType.NumberOfItems32);
// Add counter to the collection.
collection.Add(data);
// Create the category and pass the collection to it.
PerformanceCounterCategory.Create(
"DimecastDeme",
"",
PerformanceCounterCategoryType.MultiInstance,
collection);
// Get the counter already been created (Counter Name: Number of Items; Category: DimecastDeme)
var counter = new PerformanceCounter("DimecastDeme", "Number Of Items", "Demo", false);
// set value
counter.RawValue = 1;
counter.IncrementBy(2);
counter.IncrementBy(4);
var collection = new CounterCreationDataCollection();
// Create the counter and set its properties.
var data = new CounterCreationData("Number Of Items", "...", PerformanceCounterType.NumberOfItems32);
// Add counter to the collection.
collection.Add(data);
// Create the category and pass the collection to it.
PerformanceCounterCategory.Create(
"DimecastDeme",
"",
PerformanceCounterCategoryType.MultiInstance,
collection);
// Get the counter already been created (Counter Name: Number of Items; Category: DimecastDeme)
var counter = new PerformanceCounter("DimecastDeme", "Number Of Items", "Demo", false);
// set value
counter.RawValue = 1;
counter.IncrementBy(2);
counter.IncrementBy(4);
Reference:
http://msdn.microsoft.com/en-us/library/5e3s61wf.aspx
http://www.techscreencast.com/language/dotnet/how-to-create-a-custom-performance-counter/1856
作者:DylanWind
出处:http://www.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。