Problem Creating Physical Memory Monitor Using VBScript

Forum: Operations Manager4
Viewing 15 posts - 1 through 15 (of 22 total)
  • #88739
    Profile photo of jsr2993
    jsr2993
    Member

    Trying to create a monitor for a system’s physical memory, using vbscript.  Created a Scripting – Generic – Timed Script Three State Monitor.  We also enabled the  expressions to be: Property[@Name=’Status’].  Its showing healthy on our test system yet we’re seeing the CPU well over the threshold.

    Not sure where we went wrong but below is the script we’ve used:

    Dim oAPI, oBag

    Set oAPI = CreateObject(“MOM.ScriptAPI”)

    Set oBag = oAPI.CreatePropertyBag()

     

    Option Explicit

    Dim objWMIService, objItem, colItems

    Dim strComputer, strList

    Dim memused, mempercent

    On Error Resume Next

    strComputer = “.”

    Set objWMIService = GetObject(“winmgmts:\\” _

    & strComputer & “\root\cimv2”)

    Set colItems = objWMIService.ExecQuery _

    (“Select * from Win32_OperatingSystem”)

    For Each objItem in colItems

    memused = objItem.TotalVisibleMemorySize – objItem.FreePhysicalMemory

    mempercent = memused/objItem.TotalVisibleMemorySize

    mempercent = mempercent * 100

    Next

    if mempercent > 95 then

    Call oBag.AddValue(“Status”,”Critical”)

    Call oAPI.Return(oBag)

    else if mempercent > 80 then

    Call oBag.AddValue(“Status”,”Warning”)

    Call oAPI.Return(oBag)

    End If

    Else

    Call oBag.AddValue(“Status”,”Healthy”)

    Call oAPI.Return(oBag)

    End If

    #88741
    Profile photo of ComputerBob
    ComputerBob
    Participant

    What happens when you run the script yourself? If you open a command prompt and run the script, you should see the results that normally get piped back to SCOM in the property bag printed on your screen. In there you’ll see what it’s returning to SCOM as the value of ‘Status’. This will tell you if your script is the problem or if your monitor is interpreting the results incorrectly.

    I’m guessing you misstated what you were trying to say when you mentioned the CPU was over the threshold, right? Because your script and your question seems to be all about memory and nothing about the CPU.

    Also, I’m curious why you are using a script and not a Double Threshold Windows Performance Counter monitor? (I think this one is already in the Windows OS MP anyway, isn’t it?)

    And lastly, instead of hard coding the thresholds into the script, you may want to simply return the value (‘mempercent’) to SCOM and then let SCOM interpret whether it’s healthy, warning, or critical. This would allow you to use overrides to set the thresholds differently on various servers if you find you need to.

    #88742
    Profile photo of ComputerBob
    ComputerBob
    Participant

    I just copied your script over to one of my servers and it doesn’t even run.

    First, the “Option Explicit” expression has to be the first line in the script if you’re going to have it in there.  Having it where you had it made the script error when being compiled without doing anything else.

    Getting past that problem, the ‘IF / Then / Else If / End If / Else’ statements you have at the bottom are not formulated properly and just don’t work at all.

    Here’s a working version of the script that returns the memory percent value back to SCOM.  Set the thresholds in your monitor and you should be OK.

    Option Explicit
    Dim oAPI, oBag
    Set oAPI = CreateObject(“MOM.ScriptAPI”)
    Set oBag = oAPI.CreatePropertyBag()
    Dim objWMIService, objItem, colItems
    Dim strComputer, strList
    Dim memused, mempercent
    On Error Resume Next
    strComputer = “.”
    Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
    Set colItems = objWMIService.ExecQuery (“Select * from Win32_OperatingSystem”)
    For Each objItem in colItems
    memused = objItem.TotalVisibleMemorySize – objItem.FreePhysicalMemory
    mempercent = memused/objItem.TotalVisibleMemorySize
    mempercent = mempercent * 100
    Next
    Call oBag.AddValue(“mempercent”,mempercent )
    Call oAPI.Return(oBag)

    #88743
    Profile photo of jsr2993
    jsr2993
    Member

    I’m currently working to debug it now. I did indeed mean Memory instead of CPU, don’t really know where I pulled that from.

    We’re looking to use the script instead, because we want to monitor all three states of the particular system rather than a healthy or critical.

    I’ll see if I can debug it further and then go from there.

    Thanks for the assist.

    #88759
    Profile photo of Josh
    Josh
    Member

    Thanks everyone for helping us. We used your code/suggestions and came up with this script that accepts parameters for the warning and critical states so that they can be overridden.

    Option Explicit

    Dim oAPI, oBag, oArgs

    Dim objWMIService, objItem, colItems

    Dim strComputer, strList

    Dim memused, mempercent, warn, crit

    Set oAPI = CreateObject(“MOM.ScriptAPI”)

    Set oBag = oAPI.CreatePropertyBag()

    Set oArgs = WScript.Arguments

    warn = oArgs(0)

    crit = oArgs(1)

    warn = cInt(warn)

    crit = cInt(crit)

    On Error Resume Next

    strComputer = “.”

    Set objWMIService = GetObject(“winmgmts:\\” _

    & strComputer & “\root\cimv2”)

    Set colItems = objWMIService.ExecQuery _

    (“Select * from Win32_OperatingSystem”)

    For Each objItem in colItems

    memused = objItem.TotalVisibleMemorySize – objItem.FreePhysicalMemory

    mempercent = memused/objItem.TotalVisibleMemorySize

    mempercent = mempercent * 100

    mempercent = Cint(mempercent)

    Next

    if mempercent >= warn then

    if mempercent < crit then Call oBag.AddValue(“Status”,”Warning”) Call oBag.AddValue(“Percent”,mempercent) Call oAPI.Return(oBag) End if End if if mempercent >= crit then

    Call oBag.AddValue(“Status”,”Critical”)

    Call oBag.AddValue(“Percent”,mempercent)

    Call oAPI.Return(oBag)

    End If

    if mempercent < warn then Call oBag.AddValue(“Status”,”Healthy”) Call oBag.AddValue(“Percent”,mempercent) Call oAPI.Return(oBag) End If

    #88761
    Profile photo of Josh
    Josh
    Member

    And to answer the question as to why we aren’t using the windows performance counter, is this is not available as a performance counter. There is one named % Committed bytes in use, however that includes the pagefile into the calculation.

    This one is only the % physical memory. hHich is the same number you see on the bottom right of task manager for “physical memory” Searched all over WMI and Perfmon for it and couldn’t locate this being available without doing the calculation yourself.

    #216076
    Profile photo of Sam
    Sam
    Participant

    Can anyone let me know how can i use this the above script to create a monitor and monitor physical memory?

    #216077
    Profile photo of Pete Zerger
    Pete Zerger
    Keymaster

    Yes, I have a tutorial I wrote back in the SCOM 2007 days that works exactly the same in 2012:

    While you are at it, look at our other scripts you can use in the same way at

    Links: OpsMgr 2007 / 2012 Scripting Articles at System Center Central

     

     

    #216173
    Profile photo of Sam
    Sam
    Participant

    Thank you Pete. I have gone through that document and created the monitor. But i am not able to provide the threshold values for the monitor.

    #216363
    Profile photo of Sam
    Sam
    Participant

    I am receiving the error message after providing the values for the monitor. Can anyone let me know how to input the values.
    Error details, Event id:11367

    The Microsoft Operations Manager Scheduler Data Source Module failed to initialize because some “hour in the day” could not be parsed on the HH:mm format.

    Hour in the day: 80

    One or more workflows were affected by this.

    Workflow name: UIGeneratedMonitor0a0178a3ea044f948a691aa773a60935

    #216668
    Profile photo of Bad Kitty
    Bad Kitty
    Participant

    You may have to save your MP as a .txt file and upload for us to have a look at.

    #216669
    Profile photo of Sam
    Sam
    Participant

    I am attaching the management pack. Please have a look and suggest me how to proceed further. I have used the script which is mentioned in this thread itself.

    Attachments:
    You must be logged in to view attached files.
    #216691
    Profile photo of bradcaccamo
    bradcaccamo
    Participant

    could i show you something real quick in powershell?

    $x=@(gwmi win32_operatingsystem)
    $free=[math]::round(($x.FreePhysicalMemory/$x.TotalVisibleMemorySize)*100,0)
    write-host $free%

    wrapping it in scom makes it a little longer

    $api = new-object -comobject “mom.scriptapi”
    $bag = $api.createpropertybag()
    $x=@(gwmi win32_operatingsystem)
    $free=[math]::round(($x.FreePhysicalMemory/$x.TotalVisibleMemorySize)*100,0)
    $bag.addvalue(‘data’,$free)
    $api.return($bag)

    *changeĀ $api.return($bag) to $bag when using it in a management pack.

    vbscript needs to go to sleep.

    #216694
    Profile photo of bradcaccamo
    bradcaccamo
    Participant

    and here is this too.

    Attachments:
    You must be logged in to view attached files.
    #216701
    Profile photo of Sam
    Sam
    Participant

    Thank you Bradcaccamo. I will import the management pack and get back to you if i have any queries

Viewing 15 posts - 1 through 15 (of 22 total)

You must be logged in to reply to this topic.