16 May 2011

Of Property Bags & Custom Performance Rules

This might not be the best kept secret with OpsMgr especially for those who had experience creating custom monitors/performance in OpsMgr.

Although OpsMgr provides many avenue to collect monitoring information on monitored systems (either via WMI, Perfmon etc), nevertheless at times there are still a need for us to collect information that is not available directly … or maybe the collected data needs a bit of manipulation before sending it to OpsMgr.

In this example, I will just share a simple scenario where we need to collect % Disk Utilization for a Logical Disk in a server. (Albeit OpsMgr already collects % Free Space, but I am going to flip things around in this scenario)

Let’s start things by exploring how do we get the necessary information to compute % Disk Utilization?

This is where our good friend Windows Management Instrumentation (WMI) comes into the picture. Many would know that WMI is a big repository class which stores the management information on the systems host and in this case, we need to query WMI to retrieve the information related to Logical Disk utilization.

There are many ways to achieve this (e.g Powershell, Scripts etc.) but being an old school VB guy, I will resort to VBScripts to do this.

The following are the excerpts for my code.

Const HARD_DISK = 3
Dim counter, strComputer
strComputer = "."

‘ Connect to the WMI class of root\cimv2 (which provides the systems information that we need)

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

‘ Query WMI to retrieve all Logical Disks in the local computer

Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK )

‘ Iterate each Logical Disk (e.g C:\ D:\  etc & Provide the Size of the Disk)

For Each objDisk in colDisks   

‘Compute Disk Utilization = (Size – Free Space)/Size
    l_pct_util = ((objDisk.Size  - objDisk.FreeSpace)/objDisk.Size) * 100) 


Now we have the script to collect Disk Utilization, my next posting will show how we will modify this script to collect performance data to OpsMgr using Property Bag.