다음을 통해 공유


Management Pack Health Model Exercise #12 - Creating a Script Based Performance Collection Rule

This document is part of the Operations Manager Management Pack Authoring Guide



Overview

The following procedure shows how to create a performance collection rule by using  a monitoring script in the Operations Manager 2007 Authoring console and Visual Studio Authoring Extensions. 

Product Versions

This exercise applies to the following products:

  • System Center Operations Manager 2007 R2
  • System Center 2012 Operations Manager
  • System Center 2012 Operations Manager SP1

Prerequisites

Before you perform this procedure, you must first complete the following prerequisite procedures:

Revisions

The Microsoft System Center team has validated this procedure as of Revision #1.  We will continue to review any changes and periodically provide validations on later revisions as they are made.  Please feel free to make any corrections or additions to this procedure that you think would assist other users

Sample Code

A sample of the completed code for each exercise is available in the TechNet Gallery.  There is a separate sample for each exercise that includes the management pack completed at the end of that exercise and each preceding exercise.  This strategy allows you to work through each exercise in order and then compare your results.  For VSAE, this also includes the Visual Studio solution. 

Details

The rule created in this procedure has the following characteristics:

  • Runs on any computer that has an instance of MyComputerRole1.
  • The script accepts two parameters, one for computer name and another for the version of the application that is stored as a property on the target class.
  • The script itself is only for testing and performs no real function. It simulates a script running a synthetic transaction and returning a property bag with static values.

 


Authoring Console Procedure

  1. In the Authoring Console, select Health Model, and then select Rules.
  2. Right-click in the Rules pane, select New, select Collection, select Performance Based, and then select Script Based Performance Collection.
  3. On the General page, do the following:
    1. In the ElementID box, type MyMP.Rule.CollectScriptPerformance.
    2. In the Display Name box, type My Application Collect Script Performance.
    3. In the Target box, select MyMP.MyComputerRole1.
    4. In the Category box, select PerformanceCollection. Click Next.
  4. On the Schedule page, in the Run every box, type 15 minutes.
  5. On the Script page, do the following:
    1. For the File Name value, type MyPerfCollectionScript.vbs.

    2. For the Timeout value, type 1 minutes

    3. In the Script box, paste the complete contents of the following script.

      sComputerName = WScript.Arguments(0)
      sVersion = WScript.Arguments(1)
       
      Set oAPI = CreateObject("MOM.ScriptAPI")
      Set oBag = oAPI.CreatePropertyBag()
      Call oBag.AddValue("ComputerName",sComputerName)
      Call oBag.AddValue("InstanceName","MyInstance")
      Call oBag.AddValue("Value",10)
       
      oAPI.Return(oBag)
      

       

      
      
    4. Click the Parameters button.

    5. Select Target, select (Host=Windows Computer), and then select Principal Name (Windows Computer).

    6. Type a SPACE.

    7. Select Target and then Version (My Computer Role Base).

    8. Click OK.

    9. Click Next.

  6. On the Performance Mapper page, do the following:
    1. In the Object box, type MyApp.
    2. In the Counter box, type MyCounter.
    3. In the Instance box, type $Data/Property[@Name='InstanceName']$.
    4. In the Value box, type $Data/Property[@Name='Value']$.
    5. Click Finish.

 


Visual Studio Authoring Extensions Procedure 

  1. Create the script:
    1. In Solution Explorer, right click Right click the name of the solution, select Add and then select New Item..

    2. Select VBScript File.

    3. Change the name of the script to MyPerfCollectionScript.vbs and click Add.

    4. Right-click MyPerfCollectionScript.vbs and select Open.

    5. Copy the following code into the script window:

      sComputerName = WScript.Arguments(0)
      sVersion = WScript.Arguments(1)
       
      Set oAPI = CreateObject("MOM.ScriptAPI")
      Set oBag = oAPI.CreatePropertyBag()
      Call oBag.AddValue("ComputerName",sComputerName)
      Call oBag.AddValue("InstanceName","MyInstance")
      Call oBag.AddValue("Value",10)
       
      oAPI.Return(oBag)
      
       
      
    6. Select File, and then click Save MyPerfCollectionScript.vbs.

  2. Create the Rule:
    1. In Solution Explorer, right click Rules.mptg and then select Open.
    2. Right click in the  template window and select Add Template
    3. Select Rule (Performance Collection).  
  3. Configure the Rule Properties:
    1. Right click the entry for NewPerformanceCollectionRule and select Properties Window.
    2. Change the ID to Rule.CollectScriptPerformance.
    3. Change the Display Name to My Application Collect Script Performance.
  4. Select the Rule Target:
    1. Select Target and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyComputerRole1 and click OK.
  5. Select the Rule modules:
    1. Select Data Sources and click the ellipse (...) button on the right of the field.

    2. Click Add

    3. Select Data Source Type ID and click the ellipse (...) button on the right of the field.

    4. Select Microsoft.Windows.TimedScript.PerformanceProvider and click OK.

    5. Select Data Source Configuration and click the ellipse (...) button on the right of the field.

    6. Copy the following XML into the configuration window between the <Configuration> tags.  Note that you can use Intellisense to manually type in each entry.

      
      
      
      
            <    IntervalSeconds    >900</    IntervalSeconds    >  
            <    SyncTime />
            <    ScriptName    >MyPerfCollectionScript.vbs</    ScriptName    >  
            <    Arguments    >$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Property[Type="MyMP.MyComputerRoleBase"]/Version$</    Arguments    >  
            <    ScriptBody    >$IncludeFileContent/MyPerfCollectionScript.vbs$</    ScriptBody    >  
            <    TimeoutSeconds    >60</    TimeoutSeconds    >  
            <    ObjectName    >MyApp</    ObjectName    >  
            <    CounterName    >MyCounter</    CounterName    >  
            <    InstanceName    >$Data/Property[@Name='InstanceName']$</    InstanceName    >  
            <    Value    >$Data/Property[@Name='Value']$</    Value    >  
      
    7. Click OK.

  6. Save and Compile the Project:
    1. Select File, and then click Save Rules.mptg.
    2. Select Build and then Build Solution.
    3. Ensure that you don't receive any errors.

See Also