Thursday 14 February 2013

Using Check_mk to check the Disk queue length on a windows server



Add this script to your plugins (name it as diskqueue.ps1 for example). Standard location is C:\Program Files (x86)\Check_mk\plugins

#this check returns both the disk read queue lentgh and the disk write queue length
#for all logical disks on a server in the format:
#<drive letter> <read queue length> <write queue length>

#write check name to host
Write-Host "<<<windisk_queue>>>"

#get all of the drive letters (DeviceID) of all local (DriveType 3) logical disks from wmi
$driveletters = Get-WmiObject win32_logicaldisk -Filter "DriveType='3'" | Select -ExpandProperty "DeviceID"

#get the current value for the disk read and disk write queue length and format to 2 decimal places
ForEach($driveletter In $driveletters){

$diskreadqueuelength = "{0:N2}" -f ((Get-Counter -Counter "\LogicalDisk($driveletter)\Avg. Disk Read Queue Length").countersamples | Select -ExpandProperty "CookedValue")
$diskwritequeuelength = "{0:N2}" -f ((Get-Counter -Counter "\LogicalDisk($driveletter)\Avg. Disk Write Queue Length").countersamples | Select -ExpandProperty "CookedValue")

Write-Host $driveletter $diskreadqueuelength $diskwritequeuelength

}


then add this to your /usr/share/check_mk/checks folder with the same name as the check windisk_queue

#!/bin/python

inventory_process = []
inventory_process_active = []

# the inventory version (dummy)

def inventory_windisk_queue(checkname, info):
    # begin with empty inventory
    inventory = []
    #   print checkname
    for line in info:
        drive = str(line[0])
        read = line[1]
        write = line[2]
        inventory.append ((  "%s" % drive, (read, write)  ))
        #inventory
    return inventory
 
#the actual check
def check_windisk_queue (item, params, info):
    #print item
    #print params
    print info[0][0]
    perfdata = params
    drive = str(info[0][0])
    read = info[0][1]
    write = info[0][2]

    performance =[ ( "Read", read), ("Write", write)]
    return ((0, "No checks implemented - ONLY FOR PERFORMANCE. Read %s, Write %s" % (read, write), performance ))


# checking function, service description, perf data, invenotry function
check_info['windisk_queue'] = (check_windisk_queue, "Disk Q Length",1 ,inventory_windisk_queue)

reinventory with cmk -uII
tada!

Thanks to JJ Clements for the powershell script