检测.NET PerformanceCounterCategory数据

引用内容 引用内容
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();
        }


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 90
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭