使用 PerformanceCounters 来定位特定驱动器
伙计们,我有以下代码:
using System.Diagnostics;
private PerformanceCounter diskRead = new PerformanceCounter();
private PerformanceCounter diskWrite = new PerformanceCounter();
diskRead.CategoryName = "PhysicalDisk";
diskRead.CounterName = "Disk Reads/sec";
diskRead.InstanceName = "_Total";
diskWrite.CategoryName = "PhysicalDisk";
diskWrite.CounterName = "Disk Writes/sec";
diskWrite.InstanceName = "_Total";
该代码跟踪每秒磁盘读取次数和每秒磁盘写入次数,并且工作正常。我的问题是,如何跟踪一个特定驱动器的读取和写入?我的计算机中有 3 个硬盘,现在返回的是所有 3 个硬盘的总和。如何具体选择要监控的驱动器?
Guys, I have the following code:
using System.Diagnostics;
private PerformanceCounter diskRead = new PerformanceCounter();
private PerformanceCounter diskWrite = new PerformanceCounter();
diskRead.CategoryName = "PhysicalDisk";
diskRead.CounterName = "Disk Reads/sec";
diskRead.InstanceName = "_Total";
diskWrite.CategoryName = "PhysicalDisk";
diskWrite.CounterName = "Disk Writes/sec";
diskWrite.InstanceName = "_Total";
This code keeps track of Disk Reads per second and Disk Writes per second and it works fine. My question is, how do I keep track of reads and writes of one specific drive? I have 3 hard drives in my computer and right now its returning a total of all 3 drives combined. How can I specifically chose which drive I want to monitor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将“_Total”替换为适当的驱动器号:
应该检查一下。您需要指定名称,如
“0 C: D:”
。哎呀。编辑2:
您可以使用 获取名称
并且过滤掉以数字开头的名称可能是安全的。 (_Total 也在列表中)。
You should replace "_Total" with the appropriate drive number:
Should've checked that. You need to specify the name like
"0 C: D:"
. Yikes.Edit 2:
You can get the names with
And it is probaly safe to filter out the names that start with a number. (_Total is also in the list).
使用特定的 InstanceName,而不是 _Total。使用 Perfmon.exe 查找实例名称。
Use a specific InstanceName, not _Total. Use Perfmon.exe to find the instance names.