WMI Performance counter Query issues

懵懂的女人 提交于 2019-12-14 02:17:48

问题


Is there a way to query via WMI in C# like you can do with the System.Diagnostics.PerformanceCounter class?

Simply put how can I pass it a string like \\localhost\Processor(0)\% Processor Time and it would build the correct WMI query for me?

I have huge list of counters in a flat file from a legacy program and I want to move it to a Service which just runs through the flat file and gets the value.


回答1:


You can use the WMI Performance Class Counters. An example of this would be polling the PerfDisk_LogicalDisk

ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk");
foreach (ManagementObject service in mos.Get())
{
    foreach (PropertyData data in service.Properties)
    {
        Console.WriteLine("{0} {1}", data.Name, data.Value);
    }
}


来源:https://stackoverflow.com/questions/3522949/wmi-performance-counter-query-issues

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