Share via


Management Pack Composition Exercise #3 - Creating a monitor and rule that share a script supporting cookdown

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



Overview

The following procedure shows how to create a monitor and rule based on a common data source module using 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 the original revision.  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 workflows created in this procedure have the following characteristics:

  • Rule and monitor targeted at a class that has multiple instances on an agent. Because there are multiple instances, cookdown support is required.
  • The rule collects a performance value from the script while the monitor sets its state based on the comparison of the script value to specified threshold values.
  • The monitor does not support On Demand Discovery so that it does not require that you use a probe action module to run the script.
  • The script accepts arguments for the computer name of the target object’s agent and the version of the application.
  • The script itself is only a test that generates a constant value.

 


Authoring Console Procedure

Create data source module to run script on schedule

  1. In the Authoring Console, select Type Library and then Data Sources.
  2. Right-click in the Data Sources pane and select New and then Composite Data Source.
  3. In the Choose a unique identifier box, type MyMP.DataSourceModule.MyPerformanceScriptTimed. Click OK
  4. On the General tab, do the following:
    1. In the Name box, type Timed Performance Script Data Source.
  5. On the Member Modules tab, do the following:
    1. Click Add to add a module.

    2. In the Choose Module Type box, select Microsoft.Windows.TimedScript.PropertyBagProbe.

    3. In the Module ID box, type Script. Click OK.

    4. Click the button to the right side of the IntervalSeconds box and select Promote. This will enter the text $Config/IntervalSeconds$ 

    5. Click the button to the right side of the SyncTime box and select Promote. This will enter the text $Config/SyncTime$.

    6. In the ScriptName box, type MyCookdownScript.vbs.

    7. In the Arguments box, type $Config/ComputerName$ $Config/Version$.

    8. In the TimeoutSeconds box, type 300.

    9. Click the Edit… button. This starts the custom editor.

    10. Paste the complete contents of the following script between the ScriptBody tags in the XML. Replace any text that might already exist:

             

      <![CDATA[
      sComputerName = WScript.Arguments(0)
      sVersion = WScript.Arguments(1)
      Set oAPI = CreateObject("MOM.ScriptAPI")
      oAPI.LogScriptEvent "MyCookdownScript.vbs",10,4, "Running script on "  & sComputerName & ". Version is "  & sVersion
       
      For i = 1 to 3
         Set oBag = oAPI.CreatePropertyBag()
         Call oBag.AddValue("ComputerName",sComputerName)
         Call oBag.AddValue("ComponentName","Component" & i)
         Call oBag.AddValue("Value",30)
         oAPI.AddItem(oBag)
      Next
       
      oAPI.ReturnItems
      ]]>
      
      
      
         
      
    11. Close the editor to save the script back to the module.

    12. If you receive an error that says that the IntervalSeconds parameter is invalid according to its data type, click Ignore. This error message occurs because the IntervalSeconds parameter is configured as an integer, and the Authoring Console is reading $Config/IntervalSeconds$ as a string. This variable will be replaced with an integer value when the workflow is run so the error can be ignored.

    13. Click OK to save the module configuration.

    14. Click Add to add a new module.

    15. In the Choose Module Type box, select System.Performance.DataGenericMapper.

    16. In the Module ID box, type MapToPerf. Click OK.

    17. In the ObjectName box, type MyApp.

    18. In the CounterName box, type TestCounter.

    19. In the InstanceName box, type $Data/Property[@Name='ComponentName']$

    20. In the Value box, type $Data/Property[@Name='Value']$.

    21. Click OK.

    22. In the NextModule column for the Script module, select MapToPerf.

    23. In the NextModule column for the MapToPerf module, select Module Output.           

  6. On the Configuration Schema tab, do the following:
    1. Change the Type for the IntervalSeconds parameter to Integer.
    2. Clear the Required box next to the SyncTime parameter. The SyncTime parameter is optional for this module.
    3. In the Simple Configuration Schema section, click Add to add a parameter.
    4. In the Please enter the requested value box, type ComputerName. Click OK.
    5. In the Simple Configuration Schema section, click Add to add a parameter.
    6. In the Please enter the requested value box, type Version. Click OK.
  7. On the Overrideable Parameters tab, do the following:
    1. Click Add, then IntervalSeconds.
    2. In the Choose a unique identifier box, type IntervalSeconds. Click OK
    3. Change Configuration Element to Integer
    4. Click Add, then SyncTime
    5. In the Choose a unique identifier box, type SyncTime. Click OK.
  8. On the Data Types tab, do the following:
    1. In the Output Data section, in the Data Type: box select System.Performance.Data.
  9. Click OK to save the module.
  10. Select File, and then click Save.

 

Create Data Source Module to Filter on Instance

  1. Select Type Library and then Data Sources.
  2. Right-click the Data Sources pane, select New, and then Composite Data Source.
  3. In the Choose a unique identifier box, type MyMP.DataSourceModule.MyPerformanceScriptFiltered. Click OK
  4. On the General tab, do the following:
    1. In the Name box, type Filtered Performance Script Data Source.
  5. On the Member Modules tab, do the following:
    1. Click Add to add a module.

    2. In the Choose Module Type box, select MyMP.DataSourceModule.MyPerformanceScriptTimed.

    3. In the Module ID box, type Script. Click OK.

    4. Click the button to the right side of the IntervalSeconds box and select Promote. This enters the text $Config/IntervalSeconds$.

    5. Click the button to the right side of the Computer box and select Promote. This enters the text $Config/ComputerName$.

    6. Click the button to the right side of the Version box and select Promote. This enters the text $Config/Version$.

    7. Click Edit. This starts the custom editor. The SyncTime parameter must be added manually with an XML editor. This is because the Authoring console only populates the Configuration dialog box with required parameters for the selected module. The SyncTime parameter was configured to not be required.

    8. After the line:

      <``IntervalSeconds``>$Config/IntervalSeconds$</``IntervalSeconds``>

      add the following line:

        <  SyncTime  >$Config/SyncTime$</  SyncTime  >                  
      
    9. Close the editor to add the XML back the Authoring console.  If you receive an error saying that the IntervalSeconds parameter is invalid according to its data type, click Ignore. This error message occurs because the IntervalSeconds parameter is configured as an integer, and the Authoring Console is reading $Config/IntervalSeconds$ as a string. This variable will be replaced with an integer value when the workflow is run so the error can be ignored.

    10. Click OK to save the module configuration.

    11. Click Add to add a new module.

    12. In the Choose Module Type box, select System.ExpressionFilter.

    13. In the Module ID box, type FilterComponent. Click OK.

    14. Click Configure to open the Expression dialog box.

    15. Click Insert.

    16. In the Parameter Name box type InstanceName.

    17. In the Operator box select Equals.

    18. In the Value box type $Config/ComponentName$.

    19. Click OK to save the expression.

    20. Click OK to save the module configuration.

    21. In the NextModule column for the Script module, select FilterComponent.

    22. In the NextModule column for the FilterComponent module, select Module Output.

  6. On the Configuration Schema tab, do the following:
    1. Change the Type for the IntervalSeconds parameter to Integer.
    2. In the Simple Configuration Schema section, click Add to add a parameter.
    3. In the Please enter the requested value box, type SyncTime. Click OK.
    4. Clear the Required box next to the SyncTime parameter. The SyncTime parameter is optional for this module.
    5. Click the Up arrow to the right of the Simple Configuration Schema section until the SyncTime parameter is directly under the IntervalSeconds parameter.
    6. In the Simple Configuration Schema section, click Add to add a parameter.
    7. In the Please enter the requested value box, type ComponentName. Click OK.
  7. On the Overrideable Parameters tab, do the following:
    1. Click Add and then IntervalSeconds.
    2. In the Choose a unique identifier box, type IntervalSeconds. Click OK.
    3. Change Configuration Element to Integer.
    4. Click Add and then SyncTime.
    5. In the Choose a unique identifier box, type SyncTime**.** Click OK.
  8. On the Data Types tab, do the following:
    1. Ensure the value in the Data Types box is System.Performance.Data.
  9. Click OK to save the module.
  10. Select File, and then click Save.

Create Rule to Collect Performance Data

  1. Select Health Model, then Rules.
  2. Right-click the Rules pane and select New, then Custom Rule.
  3. In the Choose a unique identifier box, type MyMP.MyAppComponent.PerformanceCollectionRule. Click OK.
  4. On the General tab, do the following:
    1. In the Name box type Collect MyApp Component performance data.
    2. In the Target box, select MyMP.MyApplicationComponent.
  5. On the Modules tab, do the following:    
    1. In the Data Sources section click Create.
    2. In the Choose Module Type box, select MyMP.DataSourceModule.MyPerformanceScriptFiltered.
    3. In the Module ID box, type DS. Click OK.
    4. Click Edit to modify the module parameters. 
    5. In the IntervalSeconds box, type 900.
    6. Clear the text in the ComputerName box. Click the button to the right of the box, select (Host=My Computer Role 1). Now select (Host=Windows Computer) and then Principal Name (Windows Computer). This enters the text $Target/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$.
    7. Clear the text in the Version box. Click the button to the right side of the box and select (Host=My Computer Role 1) and then Version (My Computer Role Base). This will enter the text $Target/Host/Property[Type="MyMP.MyComputerRoleBase"]/Version$.
    8. Clear the text in the ComponentName box. Click the button to the right of the box and select ComponentName.
    9. Click OK to save the module configuration.
    10. In the Actions section click Create.
    11. In the Choose Module Type box, select Microsoft.SystemCenter.CollectPerformanceData.
    12. In the Module ID box, type WriteToDB. Click OK.
    13. In the Actions section click Create.
    14. In the Choose Module Type box, select Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData.
    15. In the Module ID box, type WriteToDW. Click OK.
  6. Click OK.
  7. Select File, then click Save.

Create Custom Monitor Type Using Custom Data Source

  1. Select Type Library and then Monitor Types.
  2. Right-click in the Monitor Types pane and select New and then Composite Monitor Type.
  3. In the Choose a unique identifier box, type MyMP.MyApplicationComponentMonitorType. Click OK
  4. On the General tab, do the following:
    1. In the Name box, type My Application Component Monitor Type.
  5. On the States tab, do the following:
    1. Select 3 State Monitor Type.
    2. In the ID of state 1 box type UnderThreshold.
    3. In the ID of state 2 box, type OverWarningThreshold.  
    4. In the ID of state 3 box, type OverErrorThreshold.  
  6. On the Member Modules tab, do the following:
    1. Click Add to add a module.

    2. In the Choose Module Type box, select MyMP.DataSourceModule.MyPerformanceScriptFiltered.

    3. In the Module ID box, type DataSource. Click OK.

    4. Click the button to the right side of the IntervalSeconds box and select Promote . This enters the text $Config/IntervalSeconds$.

    5. Click the button to the right side of the ComputerName box and select Promote. This enters the text $Config/ComputerName$.

    6. Click the button to the right side of the Version box and select Promote. This enters the text $Config/Version$.

    7. Click the button to the right side of the ComponentName box and select Promote. This enters the text $Config/ComponentName$.

    8. Click Edit. This starts the custom editor. The SyncTime parameter must be added manually with an XML editor. This is because the Authoring console only populates the Configuration dialog box with required parameters for the selected module. The SyncTime parameter was configured to not be required.

    9. After the line:

      <``IntervalSeconds``>$Config/IntervalSeconds$</``IntervalSeconds``>

      add the following line:

        <  SyncTime  >$Config/SyncTime$</  SyncTime  >  
      
    10. Close the editor to add the XML back the Authoring console.  If you receive an error saying that the IntervalSeconds parameter is invalid according to its data type, click Ignore. This error message occurs because the IntervalSeconds parameter is configured as an integer, and the Authoring Console is reading $Config/IntervalSeconds$ as a string. This variable will be replaced with an integer value when the workflow is run so the error can be ignored.

    11. Click OK to save the module configuration.

    12. Click Add to add a new module.

    13. In the Choose Module Type box, select System.ExpressionFilter.

    14. In the Module ID box, type FilterUnderThreshold. Click OK.

    15. Click Configure to open the Expression dialog box.      

    16. Click Insert.

    17. In the Parameter Name box type Value.

    18. In the Operator box select Less than.

    19. In the Value box type $Config/WarningThreshold$. Click OK.

    20. In each >>>@Type box, change the value String to Integer.

    21. Click OK to save the expression.

    22. Click Add to add a new module.

    23. In the Choose Module Type box, select System.ExpressionFilter.

    24. In the Module ID box, type FilterOverWarningThreshold. Click OK.

    25. Click Configure to open the Expression dialog box.

    26. Click Insert.

    27. In the Parameter Name box type Value.

    28. In the Operator box select Greater than or equal to.

    29. In the Value box type $Config/WarningThreshold$. Click OK.

    30. In each >>>@Type box, change the value String to Integer.

    31. Click OK to save the expression.

    32. Click Add to add a new module.

    33. In the Choose Module Type box, select System.ExpressionFilter.

    34. In the Module ID box, type FilterOverErrorThreshold. Click OK.

    35. Click Configure to open the Expression dialog box.

    36. Click Insert.

    37. In the Parameter Name box type Value.

    38. In the Operator box select Greater than or equal to.

    39. In the Value box type $Config/ErrorThreshold$. Click OK.

    40. In each >>>@Type box, change the value String to Integer.

    41. Click OK to save the expression.

  7. On the Regular tab, do the following:
    1. Select UnderThreshold.
    2. Check the Include box next to DataSource.
    3. Check the Include box next to FilterUnderThreshold.
    4. In the Next Module box next to DataSource select FilterUnderThreshold.
    5. In the Next Module box next to FilterUnderThreshold select Monitor State Output.
    6. Select OverWarningThreshold.
    7. Check the Include box next to DataSource.
    8. Check the Include box next to FilterOverWarningThreshold.
    9. In the Next Module box next to DataSource select FilterOverWarningThreshold.
    10. In the Next Module box next to FilterOverWarningThreshold select Monitor State Output.
    11. Select OverErrorThreshold.
    12. Check the Include box next to DataSource.
    13. Check the Include box next to FilterOverErrorThreshold.
    14. In the Next Module box next to DataSource select FilterOverErrorThreshold.
    15. In the Next Module box next to FilterOverErrorThreshold select Monitor State Output.
  8. On the Configuration Schema tab, do the following:    
    1. In the Type box next to IntervalSeconds select Integer.
    2. Click Add to add a parameter.
    3. In the Please enter the requested value box type SyncTime. Click OK.
    4. Clear the Required box next to SyncTime.
    5. Click Add to add a parameter.
    6. In the Please enter the requested value box type WarningThreshold. Click OK.
    7. In the Type box next to WarningThreshold select Integer.
    8. Click Add to add a parameter.
    9. In the Please enter the requested value box type ErrorThreshold. Click OK.
    10. In the Type box next to ErrorThreshold select Integer.
  9. On the Overrideable Parameters tab, do the following:
    1. Click Add, then IntervalSeconds.
    2. In the Choose a unique identifier box type IntervalSeconds. Click OK.
    3. In the Configuration Element box for IntervalSeconds, select Integer.
    4. Click Add, then SyncTime.
    5. In the Choose a unique identifier box, type SyncTime. Click OK.
    6. Click Add, then WarningThreshold.
    7. In the Choose a unique identifier box, type WarningThreshold. Click OK.
    8. In the Configuration Element box for WarningThreshold select Integer.
    9. Click Add, then ErrorThreshold.
    10. In the Choose a unique identifier box, type ErrorThreshold. Click OK.
    11. In the Configuration Element box for ErrorThreshold select Integer.
  10. Click OK to save the module type.
  11. Select File, and then click Save.  

 

Create Monitor Based on Custom Monitor Type

  1. Select Health Model, then Monitors.
  2. In the Monitors pane, expand MyMP.MyApplicationComponent and System.Health.EntityState.
  3. Right-click System.Health.PerformanceState, select New, and then Custom Unit Monitor
  4. In the Choose a unique identifier box, type MyMP.MyAppComponent.PerformanceMonitor. Click OK
  5. On the General tab, do the following:
    1. In the Name box, type My Application Component Performance.
  6. On the Configuration tab, do the following:
    1. Click Browse for a type.
    2. In the Choose unit monitor type box, select MyMP.MyApplicationComponentMonitorType. Click OK.
    3. In the IntervalSeconds box type 900.
    4. Clear the text in the ComputerName box. Click the button to the right side of the box, select (Host=My Computer Role 1), and then (Host=Windows Computer) and then Principal Name (Windows Computer).
    5. Clear the text in the Version box. Click the button to the right side of the box, select (Host=My Computer Role 1), and then Version (My Computer Role Base).
    6. Clear the text in the ComponentName box. Click the button to the right side of the box and select ComponentName.
    7. In the WarningThreshold box type 10.
    8. In the ErrorThreshold box type 20.
  7. On the Health tab, do the following:
    1. In the Health State box for UnderThreshold select Healthy.
    2. In the Health State box for OverWarningThreshold select Warning.
    3. In the Health State box for OverErrorThreshold select Critical.
  8. On the Alerting tab, do the following:
    1. Check the box next to Generate alerts for this monitor.
    2. In the Generate an alert when, select The monitor is in a critical or warning health state.
    3. In the Alert name: box, type Performance problem detected.
  9. Click OK to save the monitor.
  10. Select File, then click Save.

 


Visual Studio Authoring Extensions Procedure

Create data source module to run script on schedule

The first data source module will run the script and map its output to performance data.  The script is intended to return data for each instance of the target class.  In the case of this example, the script just returns three property bags to illustrate the concept. 

Since the values for the parameters provided to the module will be the same for all instances, the module is able to cookdown.  It runs only one instance of the script but returns multiple performance data items.  Each data item includes the name of the component so that we know which component each data item belongs to.

  1. Create the script:
    1. In Solution Explorer, expand the Composition folder.

    2. Right click the Composition folder, select Add and then select New Item.

    3. Select VBScript File.

    4. Change the name of the script to MyCookdownScript.vbs and click Add.

    5. Right-click MyCookdownScript.vbs and select Open.

    6. Copy the following code into the script window:

      
      
      
      
            sComputerName = WScript.Arguments(0)  
            sVersion = WScript.Arguments(1)  
            Set oAPI = CreateObject("MOM.ScriptAPI")
            oAPI.LogScriptEvent     "MyCookdownScript.vbs"    ,10,4,     "Running script on "  & sComputerName & ". Version is "  & sVersion
         
            For i = 1 to 3
                         Set oBag = oAPI.CreatePropertyBag()  
                         Call oBag.AddValue("ComputerName",sComputerName)  
                         Call oBag.AddValue("ComponentName","Component" & i)  
                         Call oBag.AddValue("Value",30)  
                         oAPI.AddItem(oBag)      
            Next  
         
            oAPI.ReturnItems  
      

                    
                     

       
      
    7. Select File, and then click Save MyCookdownScript.vbs.

  2. Create the Data Source module. 
    1. Right click MyTransactionModules.mpx and select Open.

    2. Copy the following XML into the configuration window after the last <DataSourceModuleType>.  Note that you can use Intellisense to manually type in each entry.

      <DataSourceModuleType ID="MyMP.DataSourceModule.MyPerformanceScriptTimed" Accessibility="Internal" Batching="false">
        <Configuration>
          <xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer" />
          <xsd:element minOccurs="0" name="SyncTime" type="xsd:string" />
          <xsd:element minOccurs="1" name="ComputerName" type="xsd:string" />
          <xsd:element minOccurs="1" name="Version" type="xsd:string" />
        </Configuration>
        <OverrideableParameters>
          <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
          <OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
        </OverrideableParameters>
        <ModuleImplementation Isolation="Any">
          <Composite>
            <MemberModules>
              <DataSource ID="Script" TypeID="Windows!Microsoft.Windows.TimedScript.PropertyBagProvider">
                <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
                <SyncTime>$Config/SyncTime$</SyncTime>
                <ScriptName>MyCookdownScript.vbs</ScriptName>
                <Arguments>$Config/ComputerName$ $Config/Version$</Arguments>
                <ScriptBody>$IncludeFileContent/Composition/MyCookdownScript.vbs$</ScriptBody>
                <TimeoutSeconds>300</TimeoutSeconds>
              </DataSource>
              <ConditionDetection ID="MapToPerf" TypeID="Perf!System.Performance.DataGenericMapper">
                <ObjectName>MyApp</ObjectName>
                <CounterName>TestCounter</CounterName>
                <InstanceName>$Data/Property[@Name='ComponentName']$</InstanceName>
                <Value>$Data/Property[@Name='Value']$</Value>
              </ConditionDetection>
            </MemberModules>
            <Composition>
              <Node ID="MapToPerf">
                <Node ID="Script" />
              </Node>
            </Composition>
          </Composite>
        </ModuleImplementation>
        <OutputType>Perf!System.Performance.Data</OutputType>
      </DataSourceModuleType>
      

           

Create Data Source Module to Filter on Instance

The second data source module gets the performance data from the first data source module and filters it for a single instance.  This module will output a single performance data item for a particular component. 

This module will not cookdown because a different value is provided to the ComponentName parameter for each instance of the target class.  This is a lightweight module though, so the effect of this is minimal.  The significant overhead comes from the script run from the first data source module, and that script will cookdown.

  1. Copy the following XML into the configuration window after the last <DataSourceModuleType>.  Note that you can use Intellisense to manually type in each entry.

     

    <DataSourceModuleType ID="MyMP.DataSourceModule.MyPerformanceScriptFiltered" Accessibility="Internal" Batching="false">
      <Configuration>
        <xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer" />
        <xsd:element minOccurs="0" name="SyncTime" type="xsd:string" />
        <xsd:element minOccurs="1" name="ComputerName" type="xsd:string" />
        <xsd:element minOccurs="1" name="Version" type="xsd:string" />
        <xsd:element minOccurs="1" name="ComponentName" type="xsd:string" />
      </Configuration>
      <OverrideableParameters>
        <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
        <OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
      </OverrideableParameters>
      <ModuleImplementation Isolation="Any">
        <Composite>
          <MemberModules>
            <DataSource ID="Script" TypeID="MyMP.DataSourceModule.MyPerformanceScriptTimed">
              <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
              <SyncTime>$Config/SyncTime$</SyncTime>
              <ComputerName>$Config/ComputerName$</ComputerName>
              <Version>$Config/Version$</Version>
            </DataSource>
            <ConditionDetection ID="FilterComponent" TypeID="System!System.ExpressionFilter">
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">InstanceName</XPathQuery>
                  </ValueExpression>
                  <Operator>Equal</Operator>
                  <ValueExpression>
                    <Value Type="String">$Config/ComponentName$</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
            </ConditionDetection>
          </MemberModules>
          <Composition>
            <Node ID="FilterComponent">
              <Node ID="Script" />
            </Node>
          </Composition>
        </Composite>
      </ModuleImplementation>
      <OutputType>Perf!System.Performance.Data</OutputType>
    </DataSourceModuleType>
    

     

Create Rule to Collect Performance Data

The rule calls the second data source module providing the name of the application component.

  1. Create the Rule:
    1. Right click the Composition folder and then select New Item.
    2. Select Rule (Custom).
    3. Change the name of the fragment to Rules.mptg and click Add.
  2. Configure the Rule Properties:
    1. Right click the entry for NewRule and select Properties Window.
    2. Change the ID to Rule.MyAppComponent.PerformanceCollectionRule
    3. Change the Display Name to Collect MyApp Component performance data.
    4. Change the Category to PerformanceCollection.
  3. Select the Rule Target:
    1. Select Target and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyApplicationComponent and click OK.
  4. Select and configure the data source 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 MyMP.DataSourceModule.MyPerformanceScriptFiltered 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>
      <ComputerName>$Target/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</ComputerName>
      <Version>$Target/Host/Property[Type="MyMP.MyComputerRoleBase"]/Version$</Version>
      <ComponentName>$Target/Property[Type="MyMP.MyApplicationComponent"]/ComponentName$</ComponentName>
      

             

    7. Click OK to save the module configuration.

    8. Click OK to save the data source.

  5. Select the write action modules:
    1. Select Write Actions and click the ellipse (...) button on the right of the field.
    2. Click Add.
    3. Change the Write Action ID to WriteToDB.
    4. Select Write Action Type ID and click the ellipse (...) button on the right of the field.
    5. Select Microsoft.SystemCenter.CollectPerformanceData and click OK.
    6. Click Add.
    7. Change the Write Action ID to WriteToDW.
    8. Select Write Action Type ID and click the ellipse (...) button on the right of the field.
    9. Select Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData and 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.

Create Custom Monitor Type Using Custom Data Source

The monitor type calls the data source module and defines the logic for determining different health states. 

  1. Create the Monitor Type.  This includes the health states and the configuration parameters for the monitor.  Copy the following XML into the configuration window after the last <MonitorType> tag.  Note that you can use Intellisense to manually type in each entry:
        
      

    <UnitMonitorType ID="MyMP.MyApplicationComponentMonitorType" Accessibility="Internal">
      <MonitorTypeStates>
        <MonitorTypeState ID="UnderThreshold" NoDetection="false" />
        <MonitorTypeState ID="OverWarningThreshold" NoDetection="false" />
        <MonitorTypeState ID="OverErrorThreshold" NoDetection="false" />
      </MonitorTypeStates>
      <Configuration>
        <xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer" />
        <xsd:element minOccurs="0" name="SyncTime" type="xsd:string" />
        <xsd:element minOccurs="1" name="ComputerName" type="xsd:string" />
        <xsd:element minOccurs="1" name="Version" type="xsd:string" />
        <xsd:element minOccurs="1" name="ComponentName" type="xsd:string" />
        <xsd:element minOccurs="1" name="WarningThreshold" type="xsd:integer" />
        <xsd:element minOccurs="1" name="ErrorThreshold" type="xsd:integer" />
      </Configuration>
      <OverrideableParameters>
        <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
        <OverrideableParameter ID="SyncTIme" Selector="$Config/SyncTime$" ParameterType="string" />
        <OverrideableParameter ID="WarningThreshold" Selector="$Config/WarningThreshold$" ParameterType="int" />
        <OverrideableParameter ID="ErrorThreshold" Selector="$Config/ErrorThreshold$" ParameterType="int" />
      </OverrideableParameters>
    </UnitMonitorType>
    

      

  2. Add the Data Source Module to the Monitor Type.  The values of the configuration parameters provided by the monitor are passed to the module.  Copy the following XML into the configuration window after the ending </OverideableParameters> tag.  Note that you can use Intellisense to manually type in each entry:

    <MonitorImplementation>
      <MemberModules>
        <DataSource ID="DataSource" TypeID="MyMP.DataSourceModule.MyPerformanceScriptFiltered">
          <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
          <ComputerName>$Config/ComputerName$</ComputerName>
          <Version>$Config/Version$</Version>
          <ComponentName>$Config/ComponentName$</ComponentName>
        </DataSource>
      </MemberModules>
    </MonitorImplementation>
    

          
     

  3. Add Condition Detection modules to the Monitor Type for each of the health states.  These include an expression that defines the criteria based on output from the script.  Copy the following XML into the configuration window after the <DataSource> module.  Note that you can use Intellisense to manually type in each entry:

    <``ConditionDetection ID``=``"FilterUnderThreshold" TypeID``=``"System!System.ExpressionFilter"``>

      ``<``Expression``>

        ``<``SimpleExpression``>

          ``<``ValueExpression``>

            ``<``XPathQuery Type``=``"Integer"``>Value</``XPathQuery``>

          ``</``ValueExpression``>

          ``<``Operator``>Less</``Operator``>

          ``<``ValueExpression``>

            ``<``Value Type``=``"Integer"``>$Config/WarningThreshold$</``Value``>

          ``</``ValueExpression``>

        ``</``SimpleExpression``>

      ``</``Expression``>

    </``ConditionDetection``>

    <``ConditionDetection ID``=``"FilterOverWarningThreshold" TypeID``=``"System!System.ExpressionFilter"``>

      ``<``Expression``>

        ``<``SimpleExpression``>

          ``<``ValueExpression``>

            ``<``XPathQuery Type``=``"Integer"``>Value</``XPathQuery``>

          ``</``ValueExpression``>

          ``<``Operator``>GreaterEqual</``Operator``>

          ``<``ValueExpression``>

            ``<``Value Type``=``"Integer"``>$Config/WarningThreshold$</``Value``>

          ``</``ValueExpression``>

        ``</``SimpleExpression``>

      ``</``Expression``>

    </``ConditionDetection``>

    <``ConditionDetection ID``=``"FilterOverErrorThreshold" TypeID``=``"System!System.ExpressionFilter"``>

      ``<``Expression``>

        ``<``SimpleExpression``>

          ``<``ValueExpression``>

            ``<``XPathQuery Type``=``"Integer"``>Value</``XPathQuery``>

          ``</``ValueExpression``>

          ``<``Operator``>GreaterEqual</``Operator``>

          ``<``ValueExpression``>

            ``<``Value Type``=``"Integer"``>$Config/ErrorThreshold$</``Value``>

          ``</``ValueExpression``>

        ``</``SimpleExpression``>

      ``</``Expression``>

    </``ConditionDetection``>

     

  4. Add Regular Detection to the Monitor Type.  This defines the modules that are run to determine each health state.  The module in the innermost node is run first followed by the others in the detection. Copy the following XML into the configuration window after the closing </MemberModules> tag.  Note that you can use Intellisense to manually type in each entry:

    <RegularDetections>
      <RegularDetection MonitorTypeStateID="UnderThreshold">
        <Node ID="FilterUnderThreshold">
          <Node ID="DataSource" />
        </Node>
      </RegularDetection>
      <RegularDetection MonitorTypeStateID="OverWarningThreshold">
        <Node ID="FilterOverWarningThreshold">
          <Node ID="DataSource" />
        </Node>
      </RegularDetection>
      <RegularDetection MonitorTypeStateID="OverErrorThreshold">
        <Node ID="FilterOverErrorThreshold">
          <Node ID="DataSource" />
        </Node>
      </RegularDetection>
    </RegularDetections>
    

       
       

  5. Save and Compile the Project:

    1. Select File, and then click Save MyTransactionModules.mptg.
    2. Select Build and then Build Solution.
    3. Ensure that you don't receive any errors.

Create Monitor Based on Custom Monitor Type

  1. Create the Monitor:
    1. Expand the Composition folder.
    2. Right click Monitors.mptg and then select Open.
    3. Right click in the Monitors.mptg window and select Add Template.
    4. Select Monitor (Unit) and click OK.
  2. Configure the Monitor Properties:
    1. Right click the entry for NewUnitMonitor and select Properties Window.
    2. Change the ID to Monitor.MyAppComponent.PerformanceMonitor.
    3. Change the My Application Component Performance.
  3. Select the Monitor Target:
    1. Select Target and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyApplicationComponent and click OK.
  4. Select the Monitor Type:
    1. Select Monitor Type ID and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyApplicationComponentMonitorType and click OK.
    3. Select Parent Monitor ID and click the ellipse (...) button on the right of the field.
    4. Select System.Health.PerformanceState and click OK.
  5. Configure the Monitor:
    1. Select Monitor Configuration and click the ellipse (...) button on the right of the field.

    2. 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>
      <ComputerName>$Target/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</ComputerName>
      <Version>$Target/Host/Property[Type="MyMP.MyComputerRoleBase"]/Version$</Version>
      <ComponentName>$Target/Property[Type="MyMP.MyApplicationComponent"]/ComponentName$</ComponentName>
      <WarningThreshold>10</WarningThreshold>
      <ErrorThreshold>20</ErrorThreshold>
      

             

    3. Select Monitor Operational States and click the ellipse (...) button on the right of the field.

    4. Next to UnderThreshold, select Healthy.

    5. Next to OverWarningThreshold, select Warning.

    6. Next to OverErrorThreshold, select Critical.

    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