SCOM 2012: Collecting UNIX/Linux Data with Performance Collection Rules
Performance Collection Scenarios
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*.
*
Collecting the Value of CIM Property as a Performance Counter
This example demonstrates collection of the value of a CIM property, retrieved through a WS-Man Enumeration. In this case, the PercentUserTime property of the SCX_UnixProcessStatisticalInformation class is collected for the process instance with the name: mydaemon. The data source used in this example is defined in the Microsoft.Unix.Library Management Pack.
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="true" Priority="Normal" DiscardLevel="100">
<Category>PerformanceCollection</Category>
<DataSources>
<DataSource ID="DS" TypeID="Unix!Microsoft.Unix.WSMan.PerfCounterProvider.Filtered">
<TargetSystem>$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$</TargetSystem>
<Uri>http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/##SCX_UnixProcessStatisticalInformation##?__cimnamespace=root/scx</Uri>
<Filter>##Select Name,PercentUsedMemory,PercentUserTime from SCX_UnixProcessStatisticalInformation##</Filter>
<SplitItems>true</SplitItems>
<Interval>300</Interval>
<ObjectName>##Process##</ObjectName>
<CounterName>##Percent User Time##</CounterName>
<InstanceName>##mydaemon##</InstanceName>
<InstanceProperty>##/DataItem/WsManData/*[local-name(.)='SCX_UnixProcessStatisticalInformation']/*[local-name(.)='Name'] ##</InstanceProperty>
<Value>##$Data/WsManData/*[local-name(.)='SCX_UnixProcessStatisticalInformation']/*[local-name(.)='PercentUserTime']$ ##</Value>
</DataSource>
</DataSources>
<WriteActions>
<WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectPerformanceData" />
<WriteAction ID="PublishToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData" />
</WriteActions>
</Rule>
</Rules>
</Monitoring>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="##MyMP.CollectPercentUserTime.Rule##">
<Name>##Collect Percent User Time for mydaemon##</Name>
<Description>##Description for the new rule##</Description>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPackFragment>
Collecting the Output of a Shell Command or Script as a Performance Counter
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:
- UNIX/Linux Timed Shell Command Data Source
- UNIX/Linux Timed Shell Script Data Source
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.
<ManagementPackFragment SchemaVersion="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Monitoring>
<Rules>
<Rule ID="##MyMP.MyPerfCollection.Script.Rule##" Target="##MyMP.MyCustomRole##" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>PerformanceCollection</Category>
<DataSources>
<DataSource ID="DS" TypeID="UnixAuth!Unix.Authoring.TimedShellScript.DataSource">
<Interval>300</Interval>
<TargetSystem>$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$</TargetSystem>
<ShellScript>
##<![CDATA[
echo $1
]]> ##
</ShellScript>
<ScriptArguments>55</ScriptArguments>
<Timeout>60</Timeout>
<UserName>##$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/UserName$##</UserName>
<Password>##$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/Password$##</Password>
<FilterExpression>
<RegExExpression>
<ValueExpression>
<XPathQuery>//*[local-name()="StdOut"]</XPathQuery>
</ValueExpression>
<Operator>MatchesRegularExpression</Operator>
<Pattern>^[-+]?\d*[0-9]*(\.[0-9]+)?[Ee]?[-+]?[0-9]*$</Pattern>
</RegExExpression>
</FilterExpression>
</DataSource>
</DataSources>
<ConditionDetection ID="Mapper" TypeID="Perf!System.Performance.DataGenericMapper">
<ObjectName>##MyRole##</ObjectName>
<CounterName>##MyCounter##</CounterName>
<InstanceName>##Total##</InstanceName>
<Value>$Data///*[local-name()='StdOut']$</Value>
</ConditionDetection>
<WriteActions>
<WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectPerformanceData" />
<WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData" />
</WriteActions>
</Rule>
</Rules>
</Monitoring>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="MyMP.MyPerfCollection.Script.Rule">
<Name>##Collect Script Output Peformance Value##</Name>
<Description>##Collects StdOut of a script execution as a performance counter##</Description>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPackFragment>
Collecting the Output of a Shell Command or Script as a Performance Counter – with Multiple Values
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:
- UNIX/Linux Timed Shell Command Property Bag Data Source
- UNIX/Linux Timed Shell Script Property Bag Data Source
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.
<ManagementPackFragment SchemaVersion="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Monitoring>
<Rules>
<Rule ID="##MyMP.MyPerfCollection.Command.PropertyBag.Rule##" Target="##MyMP.MyCustomRole##" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>PerformanceHealth</Category>
<DataSources>
<DataSource ID="DS" TypeID="UnixAuth!Unix.Authoring.TimedShellCommand.PropertyBag.DataSource">
<Interval>300</Interval>
<TargetSystem>$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$</TargetSystem>
<ShellCommand>##echo 'MyCounterA:88,MyCounterB:77'##</ShellCommand>
<Timeout>60</Timeout>
<UserName>##$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/UserName$##</UserName>
<Password>##$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/Password$##</Password>
<PSScriptName>##MyPSScript.ps1##</PSScriptName>
<PSScriptBody>
##<![CDATA[
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
}
}
]]> ##
</PSScriptBody>
<FilterExpression>
<RegExExpression>
<ValueExpression>
<XPathQuery>##Property[@Name='CounterValue'] ##</XPathQuery>
</ValueExpression>
<Operator>MatchesRegularExpression</Operator>
<Pattern>^[-+]?\d*[0-9]*(\.[0-9]+)?[Ee]?[-+]?[0-9]*$</Pattern>
</RegExExpression>
</FilterExpression>
</DataSource>
</DataSources>
<ConditionDetection ID="Mapper" TypeID="Perf!System.Performance.DataGenericMapper">
<ObjectName>##MyRole##</ObjectName>
<CounterName>##$Data/Property[@Name='CounterName']$ ##</CounterName>
<InstanceName>##Total##</InstanceName>
<Value>##$Data/Property[@Name='CounterValue']$ ##</Value>
</ConditionDetection>
<WriteActions>
<WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectPerformanceData" />
<WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData" />
</WriteActions>
</Rule>
</Rules>
</Monitoring>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="##MyMP.MyPerfCollection.Command.PropertyBag.Rule##">
<Name>##Collect Multiple Command Peformance Values##</Name>
<Description>##Collects multiple peformance counters from a single command execution##</Description>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPackFragment>