WMI 性能计数器查询问题

发布于 2024-09-14 22:12:18 字数 237 浏览 3 评论 0原文

有没有一种方法可以通过 C# 中的 WMI 进行查询,就像使用 System.Diagnostics.PerformanceCounter 类一样?

简而言之,我如何向它传递一个像 \\localhost\Processor(0)\% Processor Time 这样的字符串,它会为我构建正确的 WMI 查询?

我在遗留程序的平面文件中有大量计数器列表,我想将其移动到仅运行平面文件并获取值的服务。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紙鸢 2024-09-21 22:12:18

您可以使用 WMI 性能等级计数器。一个例子是轮询 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);
    }
}

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文