ATQ Average Threads Data source

Microsoft.Windows.Server.2012.R2.AD.Performance.Atq.AvgThreads.Monitor.DataSource (DataSourceModuleType)

Data source for the ATQ Average Threads monitors.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Frequencyint$Config/Frequency$FrequencyHow often the monitor is run
TimeoutSecondsint$Config/TimeoutSeconds$TimeoutTime out in seconds
WarnThresholdint$Config/WarnThreshold$Warning Threshold
ErrorThresholdint$Config/ErrorThreshold$Error Threshold
NumSamplesint$Config/NumSamples$Number of Samples
MaxPoolThreadsint$Config/MaxPoolThreads$Number of ATQ threads per processor

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.2012.R2.AD.Performance.Atq.AvgThreads.Monitor.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Frequency" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WarnThreshold" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ErrorThreshold" 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="MaxPoolThreads" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Frequency" Selector="$Config/Frequency$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="WarnThreshold" Selector="$Config/WarnThreshold$" ParameterType="int"/>
<OverrideableParameter ID="ErrorThreshold" Selector="$Config/ErrorThreshold$" ParameterType="int"/>
<OverrideableParameter ID="NumSamples" Selector="$Config/NumSamples$" ParameterType="int"/>
<OverrideableParameter ID="MaxPoolThreads" Selector="$Config/MaxPoolThreads$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/Frequency$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/Atq_Thread_Usage.vbs$ $Config/ErrorThreshold$ $Config/WarnThreshold$ $Config/NumSamples$ $Config/MaxPoolThreads$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>Atq_Thread_Usage.vbs</Name>
<Contents><Script>'*************************************************************************
' Script Name - ATQ Thread Usage Monitor
'
' Purpose - Monitors the ATQ thread usage - LDAP and Other vs. Total
'
' (c) Copyright 2015, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

SetLocale("en-us")

Sub Main()
Dim oParams, oBag, sError, oAPI, nErrorThreshold, nWarningThreshold, nIntervals, nTotalUsage, nAverageUsage, nCount
Dim nMaxPoolThreads

Set oParams = WScript.Arguments
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

if oParams.Count &lt; 4 then
sError = "The number of command line arguments is incorrect: " &amp; vbCrLf &amp; _
"Expected: 4" &amp; vbCrLf &amp; _
"Actual: " &amp; oParams.Count

oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", sError

Call oAPI.Return(oBag)
Exit Sub
End if

nErrorThreshold = CInt(oParams(0))
nWarningThreshold = CInt(oParams(1))
nIntervals = CInt(oParams(2))
nMaxPoolThreads = CInt(oParams(3))

Err.Clear
Dim oWMI,oPerfInstance, oItem, nLogicalProcessors

' Connect to WMI
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

' Get the Win32_Processor class and find the number of logical processors
Set oPerfInstance = oWMI.ExecQuery("Select * From Win32_Processor")
If Err &lt;&gt; 0 Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Failure to retrieve the CPU Configuration via WMI: " &amp; GetErrorString(Err)

Call oAPI.Return(oBag)
Exit Sub
End If

For Each oItem in oPerfInstance
nLogicalProcessors = oItem.NumberOfLogicalProcessors
Next

Dim nTotalThreadsAllowed
nTotalThreadsAllowed = nLogicalProcessors * nMaxPoolThreads

Err.Clear

On Error Resume Next

' Gather the performance data over the number of intervals specified
For nCount = 0 to nIntervals - 1

' Re-connect to WMI on each iteration
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

' Get the current snapshot
set oPerfInstance = oWMI.ExecQuery("Select * From Win32_PerfFormattedData_NTDS_NTDS")
If Err &lt;&gt; 0 Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Failure to retrieve the raw performance data for NTDS via WMI: " &amp; GetErrorString(Err)

Call oAPI.Return(oBag)
Exit Sub
End If

For Each oItem in oPerfInstance
nAverageUsage = CDbl((oItem.ATQThreadsLDAP + oItem.ATQThreadsOther) / nTotalThreadsAllowed)
Next

' Add the usage to the total
nTotalUsage = nTotalUsage + nAverageUsage

' Wait one second before grabbing the next snapshot
Wscript.Sleep(1000)
next

' Calculate the average usage over the number of intervals
nAverageUsage = CDbl(nTotalUsage / nIntervals)

' Update the monitor based on the usage vs. threshold.
' If we're over the threshold, add the relevant data to be bubbled up into the alert body.
If nAverageUsage &gt; nErrorThreshold Then
sError = "The ATQ Thread pool utilization is currently at: " &amp; FormatNumber(nAverageUsage,2) &amp; "%" &amp; vbCrLf &amp; _
"Intervals: " &amp; nIntervals &amp; vbCrLf &amp; _
"Threshold: " &amp; nErrorThreshold

oBag.AddValue "State", "BAD"
oBag.AddValue "Value", nAverageUsage
oBag.AddValue "ErrorString", sError
ElseIf nAverageUsage &gt; nWarningThreshold Then
sError = "The ATQ Thread pool utilization is currently at: " &amp; FormatNumber(nAverageUsage,2) &amp; "%" &amp; vbCrLf &amp; _
"Intervals: " &amp; nIntervals &amp; vbCrLf &amp; _
"Threshold: " &amp; nWarningThreshold

oBag.AddValue "State", "WARN"
oBag.AddValue "Value", nAverageUsage
oBag.AddValue "ErrorString", sError
Else
oBag.AddValue "State", "GOOD"
oBag.AddValue "Value", nAverageUsage
End If

Call oAPI.Return(oBag)

End Sub

'******************************************************************************
Function GetErrorString(oErr)
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description

On Error Resume Next
If 0 &gt;= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &amp;HFFFF0000
Const HiWord8007 = &amp;H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF

If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " &amp; (lErr And LoWordMask))

Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErr = strMessage
End If
End If
End If

GetErrorString = vbCrLf &amp; "The error returned was: '" &amp; strErr &amp; "' (0x" &amp; Hex(lErr) &amp; ")"
End Function

Call Main()</Script></Contents>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>