检测.NET PerformanceCounterCategory数据
作者:PaulLeder 日期:2010-07-18
引用内容public static void GetCategoryNameList()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("");
PerformanceCounterCategory[] myCat2;
myCat2 = PerformanceCounterCategory.GetCategories();
for (int i = 0; i < myCat2.Length; i++)
{
string categoryName = myCat2[i].CategoryName.ToString();
sb.AppendLine("------------------ Category【" + categoryName + "】 ");
sb.AppendLine(GetInstanceNameListANDCounterNameList(categoryName));
}
//Logger.Write(Level.Info, sb.ToString());
//这里输出sb.ToString()
}
private static string GetInstanceNameListANDCounterNameList(string CategoryName)
{
string[] instanceNames;
ArrayList counters = new ArrayList();
StringBuilder sb = new StringBuilder();
PerformanceCounterCategory mycat = new PerformanceCounterCategory(CategoryName);
try
{
instanceNames = mycat.GetInstanceNames();
if (instanceNames.Length == 0)
{
counters.AddRange(mycat.GetCounters());
}
else
{
for (int i = 0; i < instanceNames.Length; i++)
{
counters.AddRange(mycat.GetCounters(instanceNames[i]));
}
}
sb.AppendLine("---------- InstanceNames");
for (int i = 0; i < instanceNames.Length; i++)
{
sb.AppendLine(instanceNames[i]);
}
sb.AppendLine("---------- CounterNames");
foreach (PerformanceCounter counter in counters)
{
sb.AppendLine(counter.CounterName);
}
sb.AppendLine("");
sb.AppendLine("");
}
catch (Exception)
{
//Console.WriteLine("Unable to list the counters for this category");
}
return sb.ToString();
}
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("");
PerformanceCounterCategory[] myCat2;
myCat2 = PerformanceCounterCategory.GetCategories();
for (int i = 0; i < myCat2.Length; i++)
{
string categoryName = myCat2[i].CategoryName.ToString();
sb.AppendLine("------------------ Category【" + categoryName + "】 ");
sb.AppendLine(GetInstanceNameListANDCounterNameList(categoryName));
}
//Logger.Write(Level.Info, sb.ToString());
//这里输出sb.ToString()
}
private static string GetInstanceNameListANDCounterNameList(string CategoryName)
{
string[] instanceNames;
ArrayList counters = new ArrayList();
StringBuilder sb = new StringBuilder();
PerformanceCounterCategory mycat = new PerformanceCounterCategory(CategoryName);
try
{
instanceNames = mycat.GetInstanceNames();
if (instanceNames.Length == 0)
{
counters.AddRange(mycat.GetCounters());
}
else
{
for (int i = 0; i < instanceNames.Length; i++)
{
counters.AddRange(mycat.GetCounters(instanceNames[i]));
}
}
sb.AppendLine("---------- InstanceNames");
for (int i = 0; i < instanceNames.Length; i++)
{
sb.AppendLine(instanceNames[i]);
}
sb.AppendLine("---------- CounterNames");
foreach (PerformanceCounter counter in counters)
{
sb.AppendLine(counter.CounterName);
}
sb.AppendLine("");
sb.AppendLine("");
}
catch (Exception)
{
//Console.WriteLine("Unable to list the counters for this category");
}
return sb.ToString();
}
评论: 0 | 引用: 0 | 查看次数: 90
发表评论
上一篇
下一篇

文章来自:
Tags:
相关日志:






