How To Monitor Disk Usage with System Center Operations Manager



Written by Michel Audet, Microsoft Premier Field Engineer.

Monitoring Disk Usage (image courtesy of thanunkorn)Monitoring how much data is stored on a particular drive and displaying it in a graph and/or report format is often requested by customers running Microsoft System Center Operations Manager. Writing a standalone VBScript or PowerShell script isn’t overly complicated, but it generally resides outside of enterprise applications and is often managed and administered by too few individuals. Surely we can use Operations Manager (i.e. OpsMgr) to perform this simple data collection?

If the Windows Server Operating System Management Pack (MP) has been imported in Operations Manager, one of the performance collection rules enabled by default will collect data from the Logical Disk\Free Megabytes performance counter on the OpsMgr agent. Performance counters can be easily collected for items that aren’t included in an imported MP. Unfortunately, there is no “disk used” performance counter available in Windows, so capturing disk usage is slightly more complicated. The good news is that we can query WMI through a script and that the Win32_LogicalDisk class has two properties—FreeSpace and Size—that  can help us calculate used storage by building a probe-based collection rule in Operations Manager.

Below are the overall steps:

  1. Develop (or find Smile) a script to calculate the disk storage used on a logical disk.
  2. Create a probe-based performance collection rule with the script.
  3. Provide the right performance mapping information.
  4. Target the rule appropriately.
  5. Monitor the deployment of the rule to make sure it works.

Let’s go through the steps.

1. Develop a Script to Calculate the Disk Storage Used on a Logical Disk

Below is a script that makes a WMI query to return the free space and disk size properties of a logical disk and then uses these values to calculate the amount of data on the drive:

  1. On Error Resume Next
  2. CONST GB = 1073741824
  3.  
  4. Dim oAPI, oBag
  5. Set oAPI = CreateObject("MOM.ScriptAPI")
  6. Set oArgs = WScript.Arguments
  7. drive = oArgs(0)
  8.  
  9. strComputer = "."
  10. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  11.  
  12. Set colLogicalDisk = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DeviceID= ‘" & drive & "’")
  13.  
  14. For each objLogicalDisk in colLogicalDisk
  15. diskUsedGB = ((objLogicalDisk.size – objLogicalDisk.freespace)/GB)
  16. Next
  17.  
  18. Set oBag = oAPI.CreatePropertyBag()
  19. Call oBag.AddValue("DiskUsed",diskUsedGB)
  20. Call oAPI.Return(oBag)

A few comments on the script:

  • Line 2 defines the constant that we will use to convert the return values from bytes to gigabytes (GB).
  • Lines 4-7 are specific to scripting for OpsMgr.
  • Lines 9-16 are the core lines of this VBScript script. This is the part that should be tested outside of Operations Manager to see if it works and what values you expect to collect.
  • Lines 18-20 are also scripting for OpsMgr. In line 19, we provide the result of the calculation, “diskUsedGB”, to Operations Manager “DiskUsed”; we’ll reuse “DiskUsed” later on when specifying the performance mapping information.

2. Create a Probe-Based Performance Collection Rule

  • In the Operations Manager Administrator Console, under Authoring, expand Management Pack Objects, and click on Rules.
  • In the Actions Pane, click on Create a Rule to bring up the Create Rule Wizard window (figure 1).
  • Expand Collection Rules, then Probe Based and select Script (Performance).
  • In the Select a Rule Type screen (figure 1), under Management Pack, select the appropriate Management Pack to save this performance collection rule.
  • Click Next.

Operations Manager Administrator Console

  Figure 1 – Select a Rule Type Screen

  • In the Rule Name and Description screen (figure 2), type in a Rule name.

I prefer to prefix custom rules and monitors with my site code to make it easier to search and identify what I’ve built in my environment.

  • Notice that Rule is enabled is unchecked.

This disables the rule and will allow you to target to more specific groups, such as file servers (dynamically or explicitly defined).

  • Click Next.

Operations Manager Administrator Console - Rule Name

Figure 2 – Rule Name and Description Screen

  • In the Schedule screen (figure 3), configure how often to run the performance collection rule.

I’ve set it to 5 minutes so that I can monitor if it’s working and collect data quickly as I fine tune the rule. Once I confirm that everything works I’ll change it to something like once a day or every few days.

  • Click Next.

Operations Manager Administrator Console - Schedule

  Figure 3 – Schedule Screen

  • In the Script screen (figure 4), specify a File Name for the script and Timeoutvalue.
    • Paste the script in the Script box.
  • Click on Parameters at the bottom of the screen.

Operations Manager Administrator Console - Scripts

  Figure 4 – Script Screen

3. Provide the Right Performance Mapping Information

We need to provide the script an Operations Manager parameter for the logical drive (“oArgs”) so that the performance rule runs against each logical drive found on the system.

  • From the Script screen (figure 4), click on Parameters to bring up the Parameters screen (figure 5).

The parameter to provide to the script is $Target/Property[Type=”Windows!Microsoft.Windows.LogicalDevice”]/DeviceID$.

  • Click on Target and select Device ID (Windows Logical Hardware Component).
  • Click OK.

Script Targets

Figure 5 – Parameter Screen

  • On the next screen (figure 6), enter the performance mapping informationas shown below:
    • Object: LogicalDisk
    • Counter: <SiteCode>_DiskUsed (I prefer to use my site code as a prefix)
    • Instance: $Target/Property[Type=”Windows!Microsoft.Windows.LogicalDevice”]/DeviceID$
    • Value: $Data/Property[@Name=’DiskUsed’]$

Note that the default value for data is $Data/Property[@Name=’PerfValue’]$. The variable is referenced in the script (lines 18-20). In our script we used DiskUsed instead.

Set oBag = oAPI.CreatePropertyBag()

Call oBag.AddValue("DiskUsed",diskUsedGB)

Call oAPI.Return(oBag)

Script Performance Data Provider

Figure 6 – Performance Mapper Tab

4. Target the Rule Appropriately

Those who’ve used Operations Manager for a while will certainly have found out the hard way (we all have…) that you cannot target rules to a group. Now, here we could simply target to Windows Server 2008 Logical Disk or to Windows Server 2003 Logical Disk (both of these are part of a sealed MP) and the performance collection rule will work. If we want to target only a subset of agents (for example, file servers defined in a custom group), we would create an override to enable the rule and target the group for which we want to collect disk usage information.

5. Monitor the Deployment of the Rule

Once we save the probe, our targeted agents will begin a configuration update cycle. Under the local Event Logs, Applications, Operations Manager Events, we should see a number of events being written to the Operations Manager Application log on the agent(s) to monitor deployment. Note that if there are syntax errors with the script, they will generate warnings in the Operations Manager application event log. Once data has begun collecting and we can see it in the Performance View of the agent in the Administrator console, it’s time to change the collection interval (see figure 3, above).

The data is then available in reporting. For example:

  • In the Operations Manager Console, under Reporting, select Microsoft Generic Report Library, select Performance Detail.
  • Under Objects, click on Change.
  • In the Settings windows, select New Series, and then in the Series Details, click on Add Group and select the desired agent(s).
  • Under the Rule option, click on Browse… and Search for the performance rule created (this is where adding the site code as a prefix to the rule comes in handy).
  • Specify the instances of drives to display and click OK.

Hope you found this helpful.  Comments are welcome.

Comments (9)

  1. batb0t says:

    Hey All,

    Great post – this is exceptionally useful.

    I came across the same issue as G and D.

    For me the fix was in the Performance Mapper – the quotes around "DiskUsed" in value didn’t copy properly.
    After editing the collection rule and retyping the offending quotes manually – it worked great.

  2. shahid says:

    Hi Michel, thank you for the wondeful post, I really appreciate it.  I am trying to follow the steps to monitor disk space usage for my W2K8 servers but can't get it to work.  I am running SCOM 2012 SP1.  My problem is that when I goto "Reporting" and try to do the step below, the rule I created does not show up.

    •Under the Rule option, click on Browse… and Search for the performance rule created (this is where adding the site code as a prefix to the rule comes in handy).

    Also, one other thing.  In figure 2, what is the "Rule Category" that should be used.  Thanks for your help.

    Shahid

  3. G says:

    Hello,

    Thanks for the very detailed and useful guide!  I'm having 2 problems in getting it to work though which I hope you can help with please:

    1) As for Shahid, the rule I created is not visible when I search for it in the report creation

    2) I can see in the local event log on the monitored machines that there are problems with the deployment of the rule.  The alert in the log is:

    Module was unable to perform parameter replacement on parameter '$Data/Property[@Name=’DiskUsed’]$'

    Error: 0x80004005

    Details: Unspecified error

    I get that one alert for each volume on the monitored machine.  Could it be a permissions-type problem?  The SCOM agent is running as the local system account, so I wouldn't have thought that could be the problem?

    Many thanks once again!

    G

  4. D says:

    Hello,

    Great articles; however, I'm having the same issues as G.

    Any help from the author will be appreciated.

    Thanks,

  5. Michel Audet says:

    @Shahid, glad you found the post useful.

    There are various ways to call on the rule for a report, best delivered with screenshots. I've made an addendum / second part of the posting over at my TechNet blog. Go check it out: blogs.technet.com/…/revisiting-how-to-monitor-disk-usage-with-system-center-operations-manager.aspx

    For the rule collection, I picked "Performance Collection", which is the most logical – to me.

    Hope this helps.

    Michel

  6. Michel Audet says:

    @G, @D

    See my addendum to this post on my TechNet blog for reporting: blogs.technet.com/…/revisiting-how-to-monitor-disk-usage-with-system-center-operations-manager.aspx  

    0x80004005 – Could be permission, could also be an issue with the script if it's failing on every volume. Is it working on any instance of logical disk anywhere?

  7. Raj says:

    Hi All,

    It works for me and I got the report 🙂

    Thanks.

    Regards,

    Raj

  8. Vijayh says:

    Thanks for the post.It throws an error c:usersvld-extradesktopTest.vbs(7, 1) Microsoft VBScript runtime error: Subscript out of range

  9. karthik says:

    If our target is a linux based network device (of class Node), can we still write a vbscript that can use WMI to collect metrics on each of the nodes?

Skip to main content