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:
- Creating a New Management Pack - Create the management pack.
- Creating a Class - Create the class that is the target for the monitor.
- Creating a Monitor Based on a Custom Module – Create the Composition folder and monitor template group.
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
- In the Authoring Console, select Type Library and then Data Sources.
- Right-click in the Data Sources pane and select New and then Composite Data Source.
- In the Choose a unique identifier box, type MyMP.DataSourceModule.MyPerformanceScriptTimed. Click OK.
- On the General tab, do the following:
- In the Name box, type Timed Performance Script Data Source.
- On the Member Modules tab, do the following:
Click Add to add a module.
In the Choose Module Type box, select Microsoft.Windows.TimedScript.PropertyBagProbe.
In the Module ID box, type Script. Click OK.
Click the button to the right side of the IntervalSeconds box and select Promote. This will enter the text $Config/IntervalSeconds$
Click the button to the right side of the SyncTime box and select Promote. This will enter the text $Config/SyncTime$.
In the ScriptName box, type MyCookdownScript.vbs.
In the Arguments box, type $Config/ComputerName$ $Config/Version$.
In the TimeoutSeconds box, type 300.
Click the Edit… button. This starts the custom editor.
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 ]]>
Close the editor to save the script back to the module.
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.
Click OK to save the module configuration.
Click Add to add a new module.
In the Choose Module Type box, select System.Performance.DataGenericMapper.
In the Module ID box, type MapToPerf. Click OK.
In the ObjectName box, type MyApp.
In the CounterName box, type TestCounter.
In the InstanceName box, type $Data/Property[@Name='ComponentName']$
In the Value box, type $Data/Property[@Name='Value']$.
Click OK.
In the NextModule column for the Script module, select MapToPerf.
In the NextModule column for the MapToPerf module, select Module Output.
- On the Configuration Schema tab, do the following:
- Change the Type for the IntervalSeconds parameter to Integer.
- Clear the Required box next to the SyncTime parameter. The SyncTime parameter is optional for this module.
- In the Simple Configuration Schema section, click Add to add a parameter.
- In the Please enter the requested value box, type ComputerName. Click OK.
- In the Simple Configuration Schema section, click Add to add a parameter.
- In the Please enter the requested value box, type Version. Click OK.
- On the Overrideable Parameters tab, do the following:
- Click Add, then IntervalSeconds.
- In the Choose a unique identifier box, type IntervalSeconds. Click OK
- Change Configuration Element to Integer
- Click Add, then SyncTime
- In the Choose a unique identifier box, type SyncTime. Click OK.
- On the Data Types tab, do the following:
- In the Output Data section, in the Data Type: box select System.Performance.Data.
- Click OK to save the module.
- Select File, and then click Save.
Create Data Source Module to Filter on Instance
- Select Type Library and then Data Sources.
- Right-click the Data Sources pane, select New, and then Composite Data Source.
- In the Choose a unique identifier box, type MyMP.DataSourceModule.MyPerformanceScriptFiltered. Click OK.
- On the General tab, do the following:
- In the Name box, type Filtered Performance Script Data Source.
- On the Member Modules tab, do the following:
Click Add to add a module.
In the Choose Module Type box, select MyMP.DataSourceModule.MyPerformanceScriptTimed.
In the Module ID box, type Script. Click OK.
Click the button to the right side of the IntervalSeconds box and select Promote. This enters the text $Config/IntervalSeconds$.
Click the button to the right side of the Computer box and select Promote. This enters the text $Config/ComputerName$.
Click the button to the right side of the Version box and select Promote. This enters the text $Config/Version$.
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.
After the line:
<``IntervalSeconds``>$Config/IntervalSeconds$</``IntervalSeconds``>
add the following line:
< SyncTime >$Config/SyncTime$</ SyncTime >
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.
Click OK to save the module configuration.
Click Add to add a new module.
In the Choose Module Type box, select System.ExpressionFilter.
In the Module ID box, type FilterComponent. Click OK.
Click Configure to open the Expression dialog box.
Click Insert.
In the Parameter Name box type InstanceName.
In the Operator box select Equals.
In the Value box type $Config/ComponentName$.
Click OK to save the expression.
Click OK to save the module configuration.
In the NextModule column for the Script module, select FilterComponent.
In the NextModule column for the FilterComponent module, select Module Output.
- On the Configuration Schema tab, do the following:
- Change the Type for the IntervalSeconds parameter to Integer.
- In the Simple Configuration Schema section, click Add to add a parameter.
- In the Please enter the requested value box, type SyncTime. Click OK.
- Clear the Required box next to the SyncTime parameter. The SyncTime parameter is optional for this module.
- Click the Up arrow to the right of the Simple Configuration Schema section until the SyncTime parameter is directly under the IntervalSeconds parameter.
- In the Simple Configuration Schema section, click Add to add a parameter.
- In the Please enter the requested value box, type ComponentName. Click OK.
- On the Overrideable Parameters tab, do the following:
- Click Add and then IntervalSeconds.
- In the Choose a unique identifier box, type IntervalSeconds. Click OK.
- Change Configuration Element to Integer.
- Click Add and then SyncTime.
- In the Choose a unique identifier box, type SyncTime**.** Click OK.
- On the Data Types tab, do the following:
- Ensure the value in the Data Types box is System.Performance.Data.
- Click OK to save the module.
- Select File, and then click Save.
Create Rule to Collect Performance Data
- Select Health Model, then Rules.
- Right-click the Rules pane and select New, then Custom Rule.
- In the Choose a unique identifier box, type MyMP.MyAppComponent.PerformanceCollectionRule. Click OK.
- On the General tab, do the following:
- In the Name box type Collect MyApp Component performance data.
- In the Target box, select MyMP.MyApplicationComponent.
- On the Modules tab, do the following:
- In the Data Sources section click Create.
- In the Choose Module Type box, select MyMP.DataSourceModule.MyPerformanceScriptFiltered.
- In the Module ID box, type DS. Click OK.
- Click Edit to modify the module parameters.
- In the IntervalSeconds box, type 900.
- 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$.
- 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$.
- Clear the text in the ComponentName box. Click the button to the right of the box and select ComponentName.
- Click OK to save the module configuration.
- In the Actions section click Create.
- In the Choose Module Type box, select Microsoft.SystemCenter.CollectPerformanceData.
- In the Module ID box, type WriteToDB. Click OK.
- In the Actions section click Create.
- In the Choose Module Type box, select Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData.
- In the Module ID box, type WriteToDW. Click OK.
- Click OK.
- Select File, then click Save.
Create Custom Monitor Type Using Custom Data Source
- Select Type Library and then Monitor Types.
- Right-click in the Monitor Types pane and select New and then Composite Monitor Type.
- In the Choose a unique identifier box, type MyMP.MyApplicationComponentMonitorType. Click OK.
- On the General tab, do the following:
- In the Name box, type My Application Component Monitor Type.
- On the States tab, do the following:
- Select 3 State Monitor Type.
- In the ID of state 1 box type UnderThreshold.
- In the ID of state 2 box, type OverWarningThreshold.
- In the ID of state 3 box, type OverErrorThreshold.
- On the Member Modules tab, do the following:
Click Add to add a module.
In the Choose Module Type box, select MyMP.DataSourceModule.MyPerformanceScriptFiltered.
In the Module ID box, type DataSource. Click OK.
Click the button to the right side of the IntervalSeconds box and select Promote . This enters the text $Config/IntervalSeconds$.
Click the button to the right side of the ComputerName box and select Promote. This enters the text $Config/ComputerName$.
Click the button to the right side of the Version box and select Promote. This enters the text $Config/Version$.
Click the button to the right side of the ComponentName box and select Promote. This enters the text $Config/ComponentName$.
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.
After the line:
<``IntervalSeconds``>$Config/IntervalSeconds$</``IntervalSeconds``>
add the following line:
< SyncTime >$Config/SyncTime$</ SyncTime >
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.
Click OK to save the module configuration.
Click Add to add a new module.
In the Choose Module Type box, select System.ExpressionFilter.
In the Module ID box, type FilterUnderThreshold. Click OK.
Click Configure to open the Expression dialog box.
Click Insert.
In the Parameter Name box type Value.
In the Operator box select Less than.
In the Value box type $Config/WarningThreshold$. Click OK.
In each >>>@Type box, change the value String to Integer.
Click OK to save the expression.
Click Add to add a new module.
In the Choose Module Type box, select System.ExpressionFilter.
In the Module ID box, type FilterOverWarningThreshold. Click OK.
Click Configure to open the Expression dialog box.
Click Insert.
In the Parameter Name box type Value.
In the Operator box select Greater than or equal to.
In the Value box type $Config/WarningThreshold$. Click OK.
In each >>>@Type box, change the value String to Integer.
Click OK to save the expression.
Click Add to add a new module.
In the Choose Module Type box, select System.ExpressionFilter.
In the Module ID box, type FilterOverErrorThreshold. Click OK.
Click Configure to open the Expression dialog box.
Click Insert.
In the Parameter Name box type Value.
In the Operator box select Greater than or equal to.
In the Value box type $Config/ErrorThreshold$. Click OK.
In each >>>@Type box, change the value String to Integer.
Click OK to save the expression.
- On the Regular tab, do the following:
- Select UnderThreshold.
- Check the Include box next to DataSource.
- Check the Include box next to FilterUnderThreshold.
- In the Next Module box next to DataSource select FilterUnderThreshold.
- In the Next Module box next to FilterUnderThreshold select Monitor State Output.
- Select OverWarningThreshold.
- Check the Include box next to DataSource.
- Check the Include box next to FilterOverWarningThreshold.
- In the Next Module box next to DataSource select FilterOverWarningThreshold.
- In the Next Module box next to FilterOverWarningThreshold select Monitor State Output.
- Select OverErrorThreshold.
- Check the Include box next to DataSource.
- Check the Include box next to FilterOverErrorThreshold.
- In the Next Module box next to DataSource select FilterOverErrorThreshold.
- In the Next Module box next to FilterOverErrorThreshold select Monitor State Output.
- On the Configuration Schema tab, do the following:
- In the Type box next to IntervalSeconds select Integer.
- Click Add to add a parameter.
- In the Please enter the requested value box type SyncTime. Click OK.
- Clear the Required box next to SyncTime.
- Click Add to add a parameter.
- In the Please enter the requested value box type WarningThreshold. Click OK.
- In the Type box next to WarningThreshold select Integer.
- Click Add to add a parameter.
- In the Please enter the requested value box type ErrorThreshold. Click OK.
- In the Type box next to ErrorThreshold select Integer.
- On the Overrideable Parameters tab, do the following:
- Click Add, then IntervalSeconds.
- In the Choose a unique identifier box type IntervalSeconds. Click OK.
- In the Configuration Element box for IntervalSeconds, select Integer.
- Click Add, then SyncTime.
- In the Choose a unique identifier box, type SyncTime. Click OK.
- Click Add, then WarningThreshold.
- In the Choose a unique identifier box, type WarningThreshold. Click OK.
- In the Configuration Element box for WarningThreshold select Integer.
- Click Add, then ErrorThreshold.
- In the Choose a unique identifier box, type ErrorThreshold. Click OK.
- In the Configuration Element box for ErrorThreshold select Integer.
- Click OK to save the module type.
- Select File, and then click Save.
Create Monitor Based on Custom Monitor Type
- Select Health Model, then Monitors.
- In the Monitors pane, expand MyMP.MyApplicationComponent and System.Health.EntityState.
- Right-click System.Health.PerformanceState, select New, and then Custom Unit Monitor.
- In the Choose a unique identifier box, type MyMP.MyAppComponent.PerformanceMonitor. Click OK.
- On the General tab, do the following:
- In the Name box, type My Application Component Performance.
- On the Configuration tab, do the following:
- Click Browse for a type.
- In the Choose unit monitor type box, select MyMP.MyApplicationComponentMonitorType. Click OK.
- In the IntervalSeconds box type 900.
- 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).
- 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).
- Clear the text in the ComponentName box. Click the button to the right side of the box and select ComponentName.
- In the WarningThreshold box type 10.
- In the ErrorThreshold box type 20.
- On the Health tab, do the following:
- In the Health State box for UnderThreshold select Healthy.
- In the Health State box for OverWarningThreshold select Warning.
- In the Health State box for OverErrorThreshold select Critical.
- On the Alerting tab, do the following:
- Check the box next to Generate alerts for this monitor.
- In the Generate an alert when, select The monitor is in a critical or warning health state.
- In the Alert name: box, type Performance problem detected.
- Click OK to save the monitor.
- 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.
- Create the script:
In Solution Explorer, expand the Composition folder.
Right click the Composition folder, select Add and then select New Item.
Select VBScript File.
Change the name of the script to MyCookdownScript.vbs and click Add.
Right-click MyCookdownScript.vbs and select Open.
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
Select File, and then click Save MyCookdownScript.vbs.
- Create the Data Source module.
Right click MyTransactionModules.mpx and select Open.
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.
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.
- Create the Rule:
- Right click the Composition folder and then select New Item.
- Select Rule (Custom).
- Change the name of the fragment to Rules.mptg and click Add.
- Configure the Rule Properties:
- Right click the entry for NewRule and select Properties Window.
- Change the ID to Rule.MyAppComponent.PerformanceCollectionRule
- Change the Display Name to Collect MyApp Component performance data.
- Change the Category to PerformanceCollection.
- Select the Rule Target:
- Select Target and click the ellipse (...) button on the right of the field.
- Select MyMP.MyApplicationComponent and click OK.
- Select and configure the data source modules:
Select Data Sources and click the ellipse (...) button on the right of the field.
Click Add.
Select Data Source Type ID and click the ellipse (...) button on the right of the field.
Select MyMP.DataSourceModule.MyPerformanceScriptFiltered and click OK.
Select Data Source Configuration and click the ellipse (...) button on the right of the field.
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>
Click OK to save the module configuration.
Click OK to save the data source.
- Select the write action modules:
- Select Write Actions and click the ellipse (...) button on the right of the field.
- Click Add.
- Change the Write Action ID to WriteToDB.
- Select Write Action Type ID and click the ellipse (...) button on the right of the field.
- Select Microsoft.SystemCenter.CollectPerformanceData and click OK.
- Click Add.
- Change the Write Action ID to WriteToDW.
- Select Write Action Type ID and click the ellipse (...) button on the right of the field.
- Select Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData and click OK.
- Save and Compile the Project:
-
- Select File, and then click Save Rules.mptg.
- Select Build and then Build Solution.
- 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.
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>
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>
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``>
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>
Save and Compile the Project:
- Select File, and then click Save MyTransactionModules.mptg.
- Select Build and then Build Solution.
- Ensure that you don't receive any errors.
Create Monitor Based on Custom Monitor Type
- Create the Monitor:
- Expand the Composition folder.
- Right click Monitors.mptg and then select Open.
- Right click in the Monitors.mptg window and select Add Template.
- Select Monitor (Unit) and click OK.
- Configure the Monitor Properties:
- Right click the entry for NewUnitMonitor and select Properties Window.
- Change the ID to Monitor.MyAppComponent.PerformanceMonitor.
- Change the My Application Component Performance.
- Select the Monitor Target:
- Select Target and click the ellipse (...) button on the right of the field.
- Select MyMP.MyApplicationComponent and click OK.
- Select the Monitor Type:
- Select Monitor Type ID and click the ellipse (...) button on the right of the field.
- Select MyMP.MyApplicationComponentMonitorType and click OK.
- Select Parent Monitor ID and click the ellipse (...) button on the right of the field.
- Select System.Health.PerformanceState and click OK.
- Configure the Monitor:
Select Monitor Configuration and click the ellipse (...) button on the right of the field.
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>
Select Monitor Operational States and click the ellipse (...) button on the right of the field.
Next to UnderThreshold, select Healthy.
Next to OverWarningThreshold, select Warning.
Next to OverErrorThreshold, select Critical.
Click OK,
- Save and Compile the Project:
- Select File, and then click Save Rules.mptg.
- Select Build and then Build Solution.
- Ensure that you don't receive any errors.