Windows CPU Utilization Monitor Type

Microsoft.Windows.Server.10.0.CPUUtilization.Monitortype (UnitMonitorType)

Element properties:

RunAsDefault
AccessibilityInternal
Support Monitor RecalculateFalse

Member Modules:

ID Module Type TypeId RunAs 
DS1 DataSource Microsoft.Windows.Server.10.0.CPUUtilization.ModuleType Default
ProbeActionDS ProbeAction Microsoft.Windows.Server.10.0.PowerShellPropertyBagProbe Default
FilterNotOK ConditionDetection System.ExpressionFilter Default
FilterOK ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval secondsHow frequently (in seconds) the value should be sampled.
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds
CPUPercentageThresholdint$Config/CPUPercentageThreshold$CPU Percentage Utilization Threshold
CPUQueueLengthThresholdint$Config/CPUQueueLengthThreshold$CPU Queue Length Threshold
NumSamplesint$Config/NumSamples$Number of Samples

Source Code:

<UnitMonitorType ID="Microsoft.Windows.Server.10.0.CPUUtilization.Monitortype" Accessibility="Internal">
<MonitorTypeStates>
<MonitorTypeState ID="CPUUtilizationNormal"/>
<MonitorTypeState ID="CPUUtilizationHigh"/>
</MonitorTypeStates>
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CPUPercentageThreshold" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CPUQueueLengthThreshold" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NumSamples" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CounterName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ObjectName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="InstanceName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AllInstances" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
<OverrideableParameter ID="CPUPercentageThreshold" Selector="$Config/CPUPercentageThreshold$" ParameterType="int"/>
<OverrideableParameter ID="CPUQueueLengthThreshold" Selector="$Config/CPUQueueLengthThreshold$" ParameterType="int"/>
<OverrideableParameter ID="NumSamples" Selector="$Config/NumSamples$" ParameterType="int"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource TypeID="Microsoft.Windows.Server.10.0.CPUUtilization.ModuleType" ID="DS1">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<TargetComputerName>$Config/TargetComputerName$</TargetComputerName>
<NumSamples>$Config/NumSamples$</NumSamples>
<CounterName>$Config/CounterName$</CounterName>
<ObjectName>$Config/ObjectName$</ObjectName>
<InstanceName>$Config/InstanceName$</InstanceName>
<AllInstances>$Config/AllInstances$</AllInstances>
</DataSource>
<ProbeAction ID="ProbeActionDS" TypeID="Microsoft.Windows.Server.10.0.PowerShellPropertyBagProbe">
<ScriptName>Microsoft.Windows.Server.CPUUtilization.Monitortype.ps1</ScriptName>
<PSparam>param ($CPU_PERCENTAGE_THRESHOLD, $CPU_QUEUELEN_THRESHOLD, $TargetComputer, $CPU_USAGE)</PSparam>
<ScriptBody><Script>
#Copyright (c) Microsoft Corporation. All rights reserved.

# Parameters that should be passed to this script
# 0 CPU_PERCENTAGE_THRESHOLD
# 1 CPU_QUEUELEN_THRESHOLD
# 2 Computer (FQDN)
# 3 CPU_USAGE

Function Main()
{
if ($CPU_USAGE -lt 0 -or ($CPU_USAGE - $CPU_PERCENTAGE_THRESHOLD -lt 0))
{
ReturnResults "GOOD" 0 $CPU_USAGE
exit
}

#
# Sample the queue length. If we exceed threshold, then we will wait and sample agian
# to avoid sampling a cpu spike, both have exceeded, then we have a runaway cpu.
#

$lNumProcessors = GetNumProcessors $TargetComputer

$nQueueLength = GetCpuQueueLength $TargetComputer
if ($nQueueLength -gt [long]$CPU_QUEUELEN_THRESHOLD * $lNumProcessors)
{
sleep -m 500
$nQueueLength = GetCpuQueueLength $TargetComputer
if ($nQueueLength -gt [long]$CPU_QUEUELEN_THRESHOLD * $lNumProcessors)
{
ReturnResults "BAD" $nQueueLength $CPU_USAGE
exit
}
}

ReturnResults "GOOD" $nQueueLength $CPU_USAGE
Unload-Module -ModuleName "CimCmdLets"
}

Function ReturnResults
{
param ($State, $QueueLength, $PctUsage)

$oBag = $momAPI.CreatePropertyBag()
$oBag.AddValue("State", $State)
$oBag.AddValue("QueueLength", $QueueLength)
$oBag.AddValue("PctUsage", $PctUsage)
$oBag
}

# Windows Server 2003, Windows XP, and Windows 2000: Because the NumberOfLogicalProcessors property
# is not available, NumberOfProcessors indicates the number of logical processors available in the
# system. In the case of a computer system that has two physical processors each containing two
# logical processors, the value of NumberOfProcessors is 4.
# For more information see "http://msdn2.microsoft.com/en-us/library/aa394102(VS.85).aspx"
Function GetNumProcessors($TargetComputer)
{
$WMISet = WMIGetInstanceEx $TargetComputer "root\cimv2" "Win32_ComputerSystem"
foreach ($owObj in $WMISet)
{
$error.Clear()
return $owObj.NumberOfLogicalProcessors
if ($error.Count -ne 0)
{
return $owObj.NumberOfProcessors
}
}
}

Function GetCpuQueueLength($TargetComputer)
{
$WMISet = WMIGetInstanceEx $TargetComputer "root\cimv2" "Win32_PerfRawData_PerfOS_System"
foreach ($owObj in $WMISet)
{
return $owObj.ProcessorQueueLength
}
}

Main
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>CPU_PERCENTAGE_THRESHOLD</Name>
<Value>$Config/CPUPercentageThreshold$</Value>
</Parameter>
<Parameter>
<Name>CPU_QUEUELEN_THRESHOLD</Name>
<Value>$Config/CPUQueueLengthThreshold$</Value>
</Parameter>
<Parameter>
<Name>TargetComputer</Name>
<Value>$Config/TargetComputerName$</Value>
</Parameter>
<Parameter>
<Name>CPU_USAGE</Name>
<Value>$Data/Value$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="FilterOK" TypeID="System!System.ExpressionFilter">
<Expression>
<RegExExpression>
<ValueExpression>
<XPathQuery>Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>ContainsSubstring</Operator>
<Pattern>GOOD</Pattern>
</RegExExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="FilterNotOK" TypeID="System!System.ExpressionFilter">
<Expression>
<RegExExpression>
<ValueExpression>
<XPathQuery>Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>ContainsSubstring</Operator>
<Pattern>BAD</Pattern>
</RegExExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="CPUUtilizationNormal">
<Node ID="FilterOK">
<Node ID="ProbeActionDS">
<Node ID="DS1"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="CPUUtilizationHigh">
<Node ID="FilterNotOK">
<Node ID="ProbeActionDS">
<Node ID="DS1"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>