Windows – monitoring disk i/o via wmi

hard driveioperformance-monitoringwindowswmi

I'm using WMI to monitor Windows Server 2003 and Windows Server 2008 hosts. I got all the info I wanted but the disk I/O performance.

I've tried quering the "Win32_PerfFormattedData_PerfDisk_LogicalDisk" for the "AvgDiskQueueLength", but I always get "no key" result.

The WMI service is running on both systems and I can connect to it using wbemtest without any errors.

Have I missed something or am I doing something wrong?

Best Answer

AvgDiskQueueLength is a property of the Win32_PerfFormattedData_PerfDisk_LogicalDisk class. Unless the "no key" result is something really funky, it sounds like you maybe trying to access it wrong. It should be simple property notation like

win32perf.AvgDiskQueueLength

The following code should work.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colDisks = objRefresher.AddEnum _
    (objWMIService, "win32_perfformatteddata_perfdisk_physicaldisk"). _
        objectSet
objRefresher.Refresh
For Each objDisk in colDisks
        Wscript.Echo "Average Disk Queue Length: " & vbTab &  _
           objDisk.AvgDiskQueueLength
Next

The refresher portion is really only needed if you're going to make multiple calls. Avoids having to execute the GetObject code over and over again.

You may want to research average disk queue length a bit though. I remember there being something funky about the way it's collected or reported. I might be wrong, but thought I'd mention it.