Home » Microsoft Operations Manager 2005 » Monitor file and directory size

Contoso.se

Welcome to contoso.se! My name is Anders Bengtsson and this is my blog about Azure infrastructure and system management. I am a senior engineer in the FastTrack for Azure team, part of Azure Engineering, at Microsoft.  Contoso.se has two main purposes, first as a platform to share information with the community and the second as a notebook for myself.

Everything you read here is my own personal opinion and any code is provided "AS-IS" with no warranties.

Anders Bengtsson

MVP
MVP awarded 2007,2008,2009,2010

My Books
Service Manager Unleashed
Service Manager Unleashed
Orchestrator Unleashed
Orchestrator 2012 Unleashed
OMS
Inside the Microsoft Operations Management Suite

Monitor file and directory size

This script will monitor file and directory size. It will generate performance data back to the management server. You can view this information under performance view in Operators Console or/and in reports. This first example will monitor the size C:\pagefile.sys
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\pagefile.sys")
CreatePerfData "File","File Size",objFile.Path,objFile.Size
Sub CreatePerfData(strObjectName,strCounterName,strInstanceName,numValue)
    Set objPerfData = ScriptContext.CreatePerfData
    objPerfData.ObjectName = strObjectName
    objPerfData.CounterName =strCounterName
    objPerfData.InstanceName = strInstanceName
    objPerfData.Value = numValue
    ScriptContext.Submit objPerfData
End Sub

This example will monitor the size of all subfolders under C:\ 

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
CreatePerfData "File","File Size",objSubfolder.Path,objSubfolder.Size
Next
Sub CreatePerfData(strObjectName,strCounterName,strInstanceName,numValue)
                    Set objPerfData = ScriptContext.CreatePerfData
                    objPerfData.ObjectName = strObjectName
                    objPerfData.CounterName =strCounterName
                    objPerfData.InstanceName = strInstanceName
                    objPerfData.Value = numValue
                    ScriptContext.Submit objPerfData
End Sub

  1. Insert the script as a new script in Administrator Console
  2. Create a event rule that run the script every X minute
  3. Commit configuration change and wait until the script has run
  4. Open Operator Console, click performance, click you server and choose your new FILE performance objects, click draw graph

There is a guide about how to create performance data reports at momresources.org


1 Comment

Comments are closed.