开发者

WMI Performance counter Query issues

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 hu开发者_如何学Goge 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.


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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜