These examples assume the use of the UNIX/Linux Authoring Library example MP. For more information on creating and building the MP authoring project, see Getting Started.
Note: contents located between pairs of ## characters should be customized for your environment. This includes ID and property values. Be sure to remove the ## characters before building the MP.
<
ManagementPackFragment
SchemaVersion
=
"2.0"
xmlns:xsd
"http://www.w3.org/2001/XMLSchema"
>
Monitoring
Rules
Rule
ID
"##MyMP.CollectPercentUserTime.Rule##"
Target
"##MyMP.MyCustomRole##"
Enabled
"true"
ConfirmDelivery
"false"
Remotable
Priority
"Normal"
DiscardLevel
"100"
Category
>PerformanceCollection</
DataSources
DataSource
"DS"
TypeID
"Unix!Microsoft.Unix.WSMan.PerfCounterProvider.Filtered"
TargetSystem
>$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$</
Uri
>http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/##SCX_UnixProcessStatisticalInformation##?__cimnamespace=root/scx</
Filter
>##Select Name,PercentUsedMemory,PercentUserTime from SCX_UnixProcessStatisticalInformation##</
SplitItems
>true</
Interval
>300</
ObjectName
>##Process##</
CounterName
>##Percent User Time##</
InstanceName
>##mydaemon##</
InstanceProperty
>##/DataItem/WsManData/*[local-name(.)='SCX_UnixProcessStatisticalInformation']/*[local-name(.)='Name'] ##</
Value
>##$Data/WsManData/*[local-name(.)='SCX_UnixProcessStatisticalInformation']/*[local-name(.)='PercentUserTime']$ ##</
</
WriteActions
WriteAction
"WriteToDB"
"SC!Microsoft.SystemCenter.CollectPerformanceData"
/>
"PublishToDW"
"SCDW!Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData"
LanguagePacks
LanguagePack
"ENU"
IsDefault
DisplayStrings
DisplayString
ElementID
Name
>##Collect Percent User Time for mydaemon##</
Description
>##Description for the new rule##</
Shell commands or scripts that return numeric values can be used in rules for collection of historical performance data. This example demonstrates the use of a shell script that returns a single numeric value, in a performance collection rule. A Regular Expression is used to validate that the StdOut value is numeric, prior to performing the performance data mapping. For additional information about the Data Source used in this example, as well as other shell command and shell script data sources, review the documentation of the following Data Sources in the Unix.Authoring.Library Module Reference section below:
For more information about quotes and special characters in shell commands, see the appendix section - Commands and Scripts: Quotes and Special Characters Note: contents located between pairs of ## characters should be customized for your environment. This includes ID and property values. Be sure to remove the ## characters before building the MP.
"##MyMP.MyPerfCollection.Script.Rule##"
"UnixAuth!Unix.Authoring.TimedShellScript.DataSource"
ShellScript
##
<![CDATA[
echo $1
]]>
ScriptArguments
>55</
Timeout
>60</
UserName
>##$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/UserName$##</
Password
>##$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/Password$##</
FilterExpression
RegExExpression
ValueExpression
XPathQuery
>//*[local-name()="StdOut"]</
Operator
>MatchesRegularExpression</
Pattern
>^[-+]?\d*[0-9]*(\.[0-9]+)?[Ee]?[-+]?[0-9]*$</
ConditionDetection
"Mapper"
"Perf!System.Performance.DataGenericMapper"
>##MyRole##</
>##MyCounter##</
>##Total##</
>$Data///*[local-name()='StdOut']$</
"WriteToDW"
"MyMP.MyPerfCollection.Script.Rule"
>##Collect Script Output Peformance Value##</
>##Collects StdOut of a script execution as a performance counter##</
When running a shell command or shell script, the Operations Manager UNIX/Linux agent returns StdOut, StdErr, and ReturnCode values as a single DataItem. If a shell command or script returns multiple values in its output (StdOut), and these values need to be handled as distinct DataItems, a PowerShell script can be used (in the form of a PropertyBag probe) to parse the shell command/script output, perform splitting or filtering operations, and create Property Bags. The Property Bags can then be uniquely evaluated for separate monitors or rules.
This example demonstrates the use of a Shell Command which returns multiple values in StdOut, and the use of a PowerShell Property Bag probe to parse the values and create Property Bags. The Property Bag DataItems are collected as Performance Counters. For additional information about the Data Source used in this example, as well as other shell command and shell script data sources, review the documentation of the following Data Sources in the Unix.Authoring.Library Module Reference:
For more information about quotes and special characters in shell commands, see the appendix section - Commands and Scripts: Quotes and Special Characters
"##MyMP.MyPerfCollection.Command.PropertyBag.Rule##"
>PerformanceHealth</
"UnixAuth!Unix.Authoring.TimedShellCommand.PropertyBag.DataSource"
ShellCommand
>##echo 'MyCounterA:88,MyCounterB:77'##</
PSScriptName
>##MyPSScript.ps1##</
PSScriptBody
param([string]$StdOut,[string]$StdErr,[string]$ReturnCode)
$api = New-Object -comObject 'MOM.ScriptAPI'
[array]$arCounters=$StdOut.Split(",")
ForEach($counter in $ArCounters){
$sName=$counter.Split(":")[0]
$sValue=$counter.split(":")[1].trim()
if ($sValue -ne $null){
$bag = $api.CreatePropertyBag()
$bag.AddValue("CounterName",$sName)
$bag.AddValue("CounterValue",$sValue)
$bag
}
>##Property[@Name='CounterValue'] ##</
>##$Data/Property[@Name='CounterName']$ ##</
>##$Data/Property[@Name='CounterValue']$ ##</
>##Collect Multiple Command Peformance Values##</
>##Collects multiple peformance counters from a single command execution##</