Enterprise Agent Set Throttling Parameters

AVIcode.DotNet.SystemCenter.EnterpriseAgent.SetThrottlingParameters (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
SetThrottlingParameters WriteAction Microsoft.Windows.ScriptWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
PerformancePerDomainPerMinuteint$Config/PerformancePerDomainPerMinute$Performance Per Domain Per MinuteParameter that limits performance events collected per domain per minute.
PerformancePerDomainPerHourint$Config/PerformancePerDomainPerHour$Performance Per Domain Per HourParameter that limits performance events collected per domain per hour.
PerformancePerDomainPerDayint$Config/PerformancePerDomainPerDay$Performance Per Domain Per DayParameter that limits performance events collected per domain per day.
PerformanceEventGroupsPerMinuteint$Config/PerformanceEventGroupsPerMinute$Performance Event Groups Per MinuteParameter that limits performance events in a single group per minute.
PerformanceEventGroupsPerHourint$Config/PerformanceEventGroupsPerHour$Performance Event Groups Per HourParameter that limits performance events in a single group per hour.
PerformanceEventGroupsPerDayint$Config/PerformanceEventGroupsPerDay$Performance Event Groups Per DayParameter that limits performance events in a single group per day.
ExceptionsTotalChainsPerMinuteint$Config/ExceptionsTotalChainsPerMinute$Exceptions Total Chains Per MinuteParameter that limits the entire number of caught exceptions per minute.
ExceptionsTotalChainsPerHourint$Config/ExceptionsTotalChainsPerHour$Exceptions Total Chains Per HourParameter that limits the entire number of caught exceptions per hour.
ExceptionsTotalChainsPerDayint$Config/ExceptionsTotalChainsPerDay$Exceptions Total Chains Per DayParameter that limits the entire number of caught exceptions per day.
ExceptionsPerDomainPerMinuteint$Config/ExceptionsPerDomainPerMinute$Exceptions Per Domain Per MinuteParameter that limits the number of exceptions raised in particular web application (application domain) per minute.
ExceptionsPerDomainPerHourint$Config/ExceptionsPerDomainPerHour$Exceptions Per Domain Per HourParameter that limits the number of exceptions raised in particular web application (application domain) per hour.
ExceptionsPerDomainPerDayint$Config/ExceptionsPerDomainPerDay$Exceptions Per Domain Per DayParameter that limits the number of exceptions raised in particular web application (application domain) per day.
ExceptionsEventGroupsPerMinuteint$Config/ExceptionsEventGroupsPerMinute$Exceptions Event Groups Per MinuteParameter that limits the number of exceptions for each Event Group per minute. All events in an Event Group have encountered the same Problem, and therefore have identical call stacks. The 'ExceptionsEventGroups' is a logical threshold that is not directly related to resource (CPU) usage, but prevents you from receiving an unreasonable number of the same event repeatedly.
ExceptionsEventGroupsPerHourint$Config/ExceptionsEventGroupsPerHour$Exceptions Event Groups Per HourParameter that limits the number of exceptions for each Event Group per hour. All events in an Event Group have encountered the same Problem, and therefore have identical call stacks. The 'ExceptionsEventGroups' is a logical threshold that is not directly related to resource (CPU) usage, but prevents you from receiving an unreasonable number of the same event repeatedly.
ExceptionsEventGroupsPerDayint$Config/ExceptionsEventGroupsPerDay$Exceptions Event Groups Per DayParameter that limits the number of exceptions for each Event Group per day. All events in an Event Group have encountered the same Problem, and therefore have identical call stacks. The 'ExceptionsEventGroups' is a logical threshold that is not directly related to resource (CPU) usage, but prevents you from receiving an unreasonable number of the same event repeatedly.

Source Code:

<WriteActionModuleType ID="AVIcode.DotNet.SystemCenter.EnterpriseAgent.SetThrottlingParameters" Accessibility="Public">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PerformancePerDomainPerMinute" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PerformancePerDomainPerHour" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PerformancePerDomainPerDay" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PerformanceEventGroupsPerMinute" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PerformanceEventGroupsPerHour" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PerformanceEventGroupsPerDay" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsTotalChainsPerMinute" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsTotalChainsPerHour" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsTotalChainsPerDay" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsPerDomainPerMinute" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsPerDomainPerHour" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsPerDomainPerDay" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsEventGroupsPerMinute" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsEventGroupsPerHour" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ExceptionsEventGroupsPerDay" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="PerformancePerDomainPerMinute" Selector="$Config/PerformancePerDomainPerMinute$" ParameterType="int"/>
<OverrideableParameter ID="PerformancePerDomainPerHour" Selector="$Config/PerformancePerDomainPerHour$" ParameterType="int"/>
<OverrideableParameter ID="PerformancePerDomainPerDay" Selector="$Config/PerformancePerDomainPerDay$" ParameterType="int"/>
<OverrideableParameter ID="PerformanceEventGroupsPerMinute" Selector="$Config/PerformanceEventGroupsPerMinute$" ParameterType="int"/>
<OverrideableParameter ID="PerformanceEventGroupsPerHour" Selector="$Config/PerformanceEventGroupsPerHour$" ParameterType="int"/>
<OverrideableParameter ID="PerformanceEventGroupsPerDay" Selector="$Config/PerformanceEventGroupsPerDay$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsTotalChainsPerMinute" Selector="$Config/ExceptionsTotalChainsPerMinute$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsTotalChainsPerHour" Selector="$Config/ExceptionsTotalChainsPerHour$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsTotalChainsPerDay" Selector="$Config/ExceptionsTotalChainsPerDay$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsPerDomainPerMinute" Selector="$Config/ExceptionsPerDomainPerMinute$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsPerDomainPerHour" Selector="$Config/ExceptionsPerDomainPerHour$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsPerDomainPerDay" Selector="$Config/ExceptionsPerDomainPerDay$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsEventGroupsPerMinute" Selector="$Config/ExceptionsEventGroupsPerMinute$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsEventGroupsPerHour" Selector="$Config/ExceptionsEventGroupsPerHour$" ParameterType="int"/>
<OverrideableParameter ID="ExceptionsEventGroupsPerDay" Selector="$Config/ExceptionsEventGroupsPerDay$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="SetThrottlingParameters" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>SetThrottlingParameters.vbs</ScriptName>
<Arguments>
["PerformancePerDomain",$Config/PerformancePerDomainPerMinute$,$Config/PerformancePerDomainPerHour$,$Config/PerformancePerDomainPerDay$]["PerformanceEventGroups",$Config/PerformanceEventGroupsPerMinute$,$Config/PerformanceEventGroupsPerHour$,$Config/PerformanceEventGroupsPerDay$]["ExceptionsTotalChains",$Config/ExceptionsTotalChainsPerMinute$,$Config/ExceptionsTotalChainsPerHour$,$Config/ExceptionsTotalChainsPerDay$]["ExceptionsPerDomain",$Config/ExceptionsPerDomainPerMinute$,$Config/ExceptionsPerDomainPerHour$,$Config/ExceptionsPerDomainPerDay$]["ExceptionsEventGroups",$Config/ExceptionsEventGroupsPerMinute$,$Config/ExceptionsEventGroupsPerHour$,$Config/ExceptionsEventGroupsPerDay$]
</Arguments>
<ScriptBody><Script>
On Error Resume Next

SetLocale("en-us")
HandleErrorContinue("Cannot set en-us locale")

Const AgentConfigPath = "Configuration\Standard\"
Const PMonitorDefaultConfig = "PMonitor.default.config"
Const PMonitorDefaultConfig20 = "PMonitor2_0.default.config"

'Main begin
Dim WShell : Set WShell = CreateObject("wscript.shell")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim programmFilesFolder : programmFilesFolder = GetProgrammFilesFolder()
Call HandleError("GetProgrammFilesFolder()")
Dim AVIcodeInstallPath : AVIcodeInstallPath = programmFilesFolder &amp; "\AVIcode\Intercept\SCOM2007\EnterpriseMP\"

Dim fileMutex

'Parse parameters
Dim Args : Set Args = WScript.Arguments
if Args.Count &lt; 1 then
WScript.Quit
end If

Dim limitsString : limitsString = RTrim(Trim(UCase(Replace(Args(0)," ",""))))
limitsString = Left(limitsString,Len(limitsString)-1)
limitsString = Right(limitsString,Len(limitsString)-1)

Dim limitsArr : limitsArr = Split(limitsString,"][")
Call HandleError("Cannot split string : Split('" &amp; limitsString &amp;"','][')")
Dim i : i = 0
For i=0 To UBound(limitsArr)
Dim limitArr : limitArr = Split(limitsArr(i),",")
Call HandleError("Cannot split string : Split('" &amp; limitsArr(i) &amp; "',',')")
Dim limit : Set limit = New throttingLimit
limit.Name = limitArr(0)
If IsNumeric(limitArr(1)) Then
limit.MinuteThreshold = limitArr(1)
End If
If IsNumeric(limitArr(2)) Then
limit.HourThreshold = limitArr(2)
End If
If IsNumeric(limitArr(3)) Then
limit.DayThreshold = limitArr(3)
End If
Set limitsArr(i) = limit
Next

'Set throttlong values
If IsInstallEnterpriseAgent() Then
Dim agentPath : agentPath = GetAgentPath()
Call HandleError("Cannot read value from registry.")

Dim fullThrottlingFilePath20 : fullThrottlingFilePath20 = agentPath &amp; AgentConfigPath &amp; PMonitorDefaultConfig20
Call SetThrottlingParameters(fullThrottlingFilePath20,limitsArr)
Dim fullThrottlingFilePath : fullThrottlingFilePath = agentPath &amp; AgentConfigPath &amp; PMonitorDefaultConfig
Call SetThrottlingParameters(fullThrottlingFilePath,limitsArr)
End If


'------------------ FUNCTIONS -------------------------

Function SetThrottlingParameters(configurationFile,limits)
On Error Resume Next

If CreateApplicationFileMutexFile() Then
'Prepare XMLDOM object
Dim objXMLDoc : Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
Call HandleError("Cannot create 'Microsoft.XMLDOM' object.")
objXMLDoc.async = "false"
Call HandleError("Cannot set 'async' property of object 'Microsoft.XMLDOM'.")
objXMLDoc.load(configurationFile)
Call HandleError("Cannot load file '" &amp; configurationFile &amp; "' to 'Microsoft.XMLDOM' object.")

'Update throttling values
Const xPath = "ss:configuration/ss:applicationSetting/ss:modes/ss:mode/ss:limits/limit"
Dim xmlNodes : Set xmlNodes = objXMLDoc.selectNodes(xPath)
Call HandleError("Cannot select nodes : objXMLDoc.selectNodes('"&amp; xPath &amp;"').")

Dim changesDone : changesDone = False
Dim i : i = 0
for i=0 To xmlNodes.Length-1
Dim j : j = 0
For j = 0 To UBound(limits)
If (UCase(xmlNodes(i).Attributes.getNamedItem("name").text) = limits(j).Name) Then
If (limits(j).MinuteThreshold &lt;&gt; Empty) Then
Dim perMinute : Set perMinute = xmlNodes(i).Attributes.getNamedItem("perMinute")
If (perMinute.Value &lt;&gt; limits(j).MinuteThreshold) Then
perMinute.Value = limits(j).MinuteThreshold
changesDone = True
End If
End If
If (limits(j).HourThreshold &lt;&gt; Empty) Then
Dim perHour : Set perHour = xmlNodes(i).Attributes.getNamedItem("perHour")
If (perHour.Value &lt;&gt; limits(j).HourThreshold) Then
perHour.Value = limits(j).HourThreshold
changesDone = True
End If
End If
If (limits(j).DayThreshold &lt;&gt; Empty) Then
Dim perDay : Set perDay = xmlNodes(i).Attributes.getNamedItem("perDay")
If (perDay.Value &lt;&gt; limits(j).DayThreshold) Then
perDay.Value = limits(j).DayThreshold
changesDone = True
End If
End If
End If
Next
Next

If changesDone Then
objXMLDoc.save(configurationFile)
Call HandleError("Cannot save file : objXMLDoc.save('"&amp;configurationFile&amp;"')")
End If
Call CloseApplicationFileMutexFile()
Else
LogEvent "Cannot set event throttling parameters. Object Scripting Library in use." , 2
Wscript.Quit 0
End If

End Function

Public Function GetAgentPath()
On Error Resume Next

Const AgentKeyx64 = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\AVIcode\Intercept\ServerAgent\InstallPath"
Const AgentKey = "HKEY_LOCAL_MACHINE\SOFTWARE\AVIcode\Intercept\ServerAgent\InstallPath"

Dim oShell : Set oShell = CreateObject("WScript.Shell")
call HandleError("Cannot create 'WScript.Shell' object.")

Dim strVal : strVal = oShell.RegRead(AgentKey)
If (err.number&lt;&gt;0) then
Err.Clear()
strVal = oShell.RegRead(AgentKeyx64)
End If

if strVal&lt;&gt;vbEmpty Then
GetAgentPath = strVal
Else
Call Err.Raise(err.number,"GetAgentPath","Cannot get agent path from registry")
End If
End Function

Function IsInstallEnterpriseAgent()
On Error Resume Next
Dim regKey : regKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Intercept Service\ImagePath"
Dim s : s = WShell.RegRead(regKey)
If Err &lt;&gt; 0 Then
' 0x80070003 - The system cannot find the path specified.
' 0x80070002 - The system cannot find the file specified.
If UCase(Hex(Err.number)) = UCase("80070003") Or UCase(Hex(Err.number)) = UCase("80070002") Then
Err.Clear()
IsInstallEnterpriseAgent = False
Else
HandleError("Cannot read registry key: " &amp; regKey )
End If
Else
IsInstallEnterpriseAgent = True
End If
End Function

Sub HandleError(customMessage)
If Not (Err.number = 0) Then
LogError customMessage
Wscript.Quit 0
End If
End Sub

Function HandleErrorContinue(customMessage)
HandleErrorContinue = False
If Not (Err.number = 0) Then
LogError customMessage
Err.Clear
HandleErrorContinue = True
End If
End Function

Sub LogError(customMessage)
Dim msg
If Not (Err.number = 0) Then
msg = Replace(" Error: #P1# Description: #P2# ", "#P1#", CStr(Err.number) )
msg = Replace(msg, "#P2#", Err.Description )
msg = customMessage &amp; VbCrLf &amp; msg &amp; VbCrLf
If UCase(Hex(Err.number)) = UCase("80041006") Then
msg = msg &amp; "WMI Error. Not enough memory for the operation." &amp; VbCrLf
End If
WScript.StdOut.WriteLine msg
msg = msg &amp; " [" &amp; ScriptInfo() &amp; "]"
LogEvent msg, 1
End If
End Sub

Function ScriptInfo()
Dim commandLineInfo : commandLineInfo = WScript.ScriptFullName
Dim argument
For Each argument In WScript.Arguments
commandLineInfo = commandLineInfo &amp; " """ &amp; argument &amp; """"
Next
ScriptInfo = commandLineInfo
End Function

Sub LogEvent (message, eventType)
Dim errorEventId : errorEventId = 20000
Dim oAPI0 : Set oAPI0 = CreateObject("MOM.ScriptAPI")
Call oAPI0.LogScriptEvent("AVIcode .NET Enterprise Management Pack for OpsMgr 2007", errorEventId, eventType, message)
End Sub

Function CreateApplicationFileMutexFile()
On Error Resume Next
Dim fileName : fileName = AVIcodeInstallPath &amp; "ScriptingMutex.tmp"
Dim Counter : Counter = 0
do
Err.Clear()
Set fileMutex = FSO.OpenTextFile(FileName, 2 , True)
If NOT (Err = 0) Then
WScript.Sleep Int(300 * Rnd)
Counter = Counter+1
End If
loop While (Err &lt;&gt; 0) AND (Counter &lt; 100)
If Counter &lt; 100 Then
CreateApplicationFileMutexFile = True
Else
CreateApplicationFileMutexFile = False
End If
End Function

Function CloseApplicationFileMutexFile()
On Error Resume Next
If NOT(isEmpty(fileMutex)) AND NOT(isNull(fileMutex)) Then
fileMutex.Close()
If NOT (Err = 0) Then
Err.Clear()
End If
End If
End Function

Function GetProgrammFilesFolder()
GetProgrammFilesFolder = wshell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
if GetProgrammFilesFolder = "%ProgramFiles(x86)%" Then
GetProgrammFilesFolder = wshell.ExpandEnvironmentStrings("%ProgramFiles%")
End If
End Function

Class ThrottingLimit
Public Name
Public MinuteThreshold
Public HourThreshold
Public DayThreshold
End Class

</Script></ScriptBody>
<TimeoutSeconds>600</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="SetThrottlingParameters"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.BaseData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>