Windows Processor Utilization Data Source Module

Microsoft.Windows.Server.10.0.Processor.Performance.ModuleType (DataSourceModuleType)

Monitor Processor utilization of individual Processors(Socket) on Windows Servers

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Performance.Data

Member Modules:

ID Module Type TypeId RunAs 
Scheduler DataSource System.Scheduler Default
PerfPA ProbeAction Microsoft.Windows.Server.10.0.PowerShellPerformanceProbe Default
CD ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Frequencyint$Config/Frequency$Frequency secondsHow frequently (in seconds) the value should be sampled.
TimeoutSecondsint$Config/TimeoutSeconds$Timeout seconds

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.10.0.Processor.Performance.ModuleType" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="CounterName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ObjectName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="InstanceName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Frequency" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Frequency" Selector="$Config/Frequency$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/Frequency$</Interval>
<SyncTime/>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PerfPA" TypeID="Microsoft.Windows.Server.10.0.PowerShellPerformanceProbe">
<ScriptName>Microsoft.Windows.Server.CPUSocket.Performance.ps1</ScriptName>
<PSparam/>
<ScriptBody><Script>Function Main($objMomScriptAPI)
{
$ErrorActionPreference = "SilentlyContinue"
$error.Clear()

$PerfList = New-Object System.Collections.ArrayList($null)
Get-PhysicalCpuPerfData -PerfList $PerfList

if($PerfList.Count -ne $null -and $PerfList.Count -ne 0)
{
Set-PerfDataFromList -PerfList $PerfList -objMomScriptAPI $objMomScriptAPI
}
else
{
Create-EmptyPerfData -objMomScriptAPI $objMomScriptAPI
}

Unload-Module -ModuleName "CimCmdLets"

}

Function Get-PhysicalCpuPerfData($PerfList)
{
$ErrorActionPreference = "SilentlyContinue"
$error.Clear()
if($sTargetComputer -eq $null -or $sTargetComputer -eq "")
{
$sTargetComputer="."
}
$WMISet = WMIGetInstanceNoAbort $sTargetComputer "root\cimv2" "Win32_Processor"
$LCpuCountersSet = WMIGetInstanceNoAbort $sTargetComputer "root\cimv2" "Win32_PerfFormattedData_PerfOS_Processor"
$LCpuCountersSet = Create-LCPUPerfData -LCpuCountersSet $LCpuCountersSet
$LcpuNumber = [UInt32]0

foreach ($owObj in $WMISet)
{

$PerfInstance = $owObj.DeviceID.Substring(3)
$NumberOfLCpu = $owObj.NumberOfLogicalProcessors
Get-CpuPerfData -CpuId $PerfInstance -lCpuId $LcpuNumber -LcpuNumber $NumberOfLCpu -lCpuPerfData $LCpuCountersSet -PerfList $PerfList
$LcpuNumber += $NumberOfLCpu
}

}

Function Create-LCPUPerfData($LCpuCountersSet)
{
$ErrorActionPreference = "SilentlyContinue"

$lCpuSet = @{}
$CpuNumber = [Uint32]0

$error.Clear()
foreach ($lCpuData in $LCpuCountersSet)
{
if (-Not [UInt32]::TryParse($lCpuData.Name,[ref]$CpuNumber))
{
continue
}

$PercentProcessorTime = $lCpuData.PercentProcessorTime
$PercentDPCTime = $lCpuData.PercentDPCTime
$PercentInterruptTime = $lCpuData.PercentInterruptTime

if ($null -eq $PercentProcessorTime)
{
$PercentProcessorTime = [UInt64]0
}

if ($null -eq $PercentDPCTime)
{
$PercentDPCTime = [UInt64]0
}

if ($null -eq $PercentInterruptTime)
{
$PercentInterruptTime = [UInt64]0
}



$CpuPdata = New-Object -TypeName psobject -Property @{
"PercentProcessorTime" = $lCpuData.PercentProcessorTime
"PercentDPCTime" = $lCpuData.PercentDPCTime
"PercentInterruptTime" = $lCpuData.PercentInterruptTime

}

$lCpuSet[$CpuNumber] = $CpuPdata

}


return $lCpuSet
}


Function Get-CpuPerfData($CpuId,$lCpuId,$LcpuNumber,$lCpuPerfData,$PerfList)
{
$ErrorActionPreference = "SilentlyContinue"
$error.Clear()

$MaxCpuNumber = $lCpuId + [Uint32]$LcpuNumber
$DPCTime = [UInt64]0
$ProcessorTime = [UInt64]0
$ProcessorInterrupt = [UInt64]0
$i = [UInt32]0

for ($i = $lCpuId; $i -lt $MaxCpuNumber; $i++)
{
$ProcessorTime += $lCpuPerfData[$i].PercentProcessorTime
$DPCTime += $lCpuPerfData[$i].PercentDPCTime
$ProcessorInterrupt += $lCpuPerfData[$i].PercentInterruptTime
}

#DPCTime
[void]$PerfList.Add((CreatePerformanceCounterData -strObjectName "Processor" -strCounterName "% DPC Time" -strInstanceName "$CpuId" -varValue ([math]::Round($DPCTime/$LcpuNumber,2)) ) )
#Processor Time
[void]$PerfList.Add((CreatePerformanceCounterData -strObjectName "Processor" -strCounterName "% Processor Time" -strInstanceName "$CpuId" -varValue ([math]::Round($ProcessorTime /$LcpuNumber,2)) ) )
#Processor Interrupt Time
[void]$PerfList.Add((CreatePerformanceCounterData -strObjectName "Processor" -strCounterName "% Interrupt Time" -strInstanceName "$CpuId" -varValue ([math]::Round($ProcessorInterrupt/$LcpuNumber,2)) ) )

}

Function Set-PerfDataFromList($PerfList, $objMomScriptAPI)
{
if ($null -eq $objMomScriptAPI)
{
return
}

$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$Error.Clear()
foreach($data in $PerfList)
{
#Add the values for the perf counter#s object name, counter name, instance name and the value)
if([string]::IsNullOrEmpty($data.PerfObject) )
{
continue
}

Create-PerformancePropertyBag -strObjectName $data.PerfObject -strCounterName $data.PerfCounter -strInstanceName $data.PerfInstance -varValue $data.PerfValue -objMomScriptAPI $objMomScriptAPI
}

}

Main -objMomScriptAPI $momAPI</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="CD" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">ObjectName</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/ObjectName$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">CounterName</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/CounterName$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">InstanceName</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/InstanceName$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="CD">
<Node ID="PerfPA">
<Node ID="Scheduler"/>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>SystemPerf!System.Performance.Data</OutputType>
</DataSourceModuleType>