C# PerformanceCounter list of possible Parameters?

浪子不回头ぞ 提交于 2019-12-05 13:52:57

Those can be obtained from the PerformanceCounterCategory class:

PerformanceCounterCategory[] categories = PerformanceCounterCategory.GetCategories();
foreach(var category in categories)
{
    string[] instanceNames = category.GetInstanceNames();
    foreach(string instanceName in instanceNames)
        PerformanceCounter[] counters = category.GetCounters(instanceName);
}

Here is some code that can be modified to get the counters that you desire(there are way too many to post).

All Categories will be outputted but the counters will only be outputted for the desired categories.

    private static void PrintPerformanceCounterParameters()
    {
        var sb = new StringBuilder();
        PerformanceCounterCategory[] categories = PerformanceCounterCategory.GetCategories();

        var desiredCategories = new HashSet<string> {"Process", "Memory"};

        foreach (var category in categories)
        {
            sb.AppendLine("Category: " + category.CategoryName);
            if (desiredCategories.Contains(category.CategoryName))
            {
                PerformanceCounter[] counters;
                try
                {
                    counters = category.GetCounters("devenv");
                }
                catch (Exception)
                {
                    counters = category.GetCounters();
                }

                foreach (var counter in counters)
                {
                    sb.AppendLine(counter.CounterName + ": " + counter.CounterHelp);
                }
            }
        }
        File.WriteAllText(@"C:\performanceCounters.txt", sb.ToString());
    }
Luc

You can find them on the Microsoft page by searching the category + "object". E.g., for the memory process objects, it would be like this: "performance counters process object". https://msdn.microsoft.com/en-us/library/ms804621.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!