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);
}
}
精彩评论