MSSQL on Windows: Agent Long Running Jobs

Microsoft.SQLServer.Windows.MonitorType.Agent.LongRunningJobs (UnitMonitorType)

This monitor type checks the current execution time of all agent jobs against specified time thresholds.

Element properties:

RunAsMicrosoft.SQLServer.Core.RunAs.Monitoring
AccessibilityInternal
Support Monitor RecalculateFalse

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.SQLServer.Windows.DataSource.AgentLongRunningJobs Default
CDOverThreshold1UnderThreshold2 ConditionDetection System.ExpressionFilter Default
CDOverThreshold2 ConditionDetection System.ExpressionFilter Default
CDUnderThreshold1 ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Threshold1double$Config/Threshold1$Warning Threshold (minutes)Exceeding this threshold will result in the monitor changing to at least a Warning state.
Threshold2double$Config/Threshold2$Critical Threshold (minutes)The monitor will change its state to Critical if the value exceeds this threshold. Being between this threshold and the warning threshold (inclusive) will result in the monitor being in a warning state.
IncludedJobsstring$Config/IncludedJobs$Included continuously executed jobsSome SQL Agent Jobs may run infinitely (until Agent stops). They usually have schedule type 'Start automatically when SQL Server Agent starts'. For example, SQL Server Replication often uses such jobs. These jobs lead to false alerts and by default monitor doesn't takes them in account. But there may be exclusions when such jobs run for a short time. In order to monitor such jobs one shoud define a list of these jobs' names delimited by comma.
SqlExecTimeoutSecondsint$Config/SqlExecTimeoutSeconds$Timeout for query execution (seconds)The workflow will fail and register an event, if the query execution takes longer than the specified period.
SqlTimeoutSecondsint$Config/SqlTimeoutSeconds$Timeout for database connection (seconds)The workflow will fail and register an event, if it cannot access the database during the specified period.
TimeoutSecondsint$Config/TimeoutSeconds$Timeout (seconds)Specifies the time the workflow is allowed to run before being closed and marked as failed.
IntervalSecondsint$Config/IntervalSeconds$Interval (seconds)The recurring interval of time in seconds in which to run the workflow.
SyncTimestring$Config/SyncTime$Synchronization TimeThe synchronization time specified by using a 24-hour format. May be omitted.

Source Code:

<UnitMonitorType ID="Microsoft.SQLServer.Windows.MonitorType.Agent.LongRunningJobs" Accessibility="Internal" RunAs="SqlCoreLib!Microsoft.SQLServer.Core.RunAs.Monitoring">
<MonitorTypeStates>
<MonitorTypeState ID="UnderThreshold1"/>
<MonitorTypeState ID="OverThreshold1UnderThreshold2"/>
<MonitorTypeState ID="OverThreshold2"/>
</MonitorTypeStates>
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MachineName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NetbiosComputerName" 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="ConnectionString" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="InstanceVersion" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="InstanceEdition" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MonitoringType" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Threshold1" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Threshold2" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IncludedJobs" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SqlExecTimeoutSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SqlTimeoutSeconds" 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="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SyncTime" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Threshold1" ParameterType="double" Selector="$Config/Threshold1$"/>
<OverrideableParameter ID="Threshold2" ParameterType="double" Selector="$Config/Threshold2$"/>
<OverrideableParameter ID="IncludedJobs" ParameterType="string" Selector="$Config/IncludedJobs$"/>
<OverrideableParameter ID="SqlExecTimeoutSeconds" ParameterType="int" Selector="$Config/SqlExecTimeoutSeconds$"/>
<OverrideableParameter ID="SqlTimeoutSeconds" ParameterType="int" Selector="$Config/SqlTimeoutSeconds$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="SyncTime" ParameterType="string" Selector="$Config/SyncTime$"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource TypeID="Microsoft.SQLServer.Windows.DataSource.AgentLongRunningJobs" ID="DS">
<MachineName>$Config/MachineName$</MachineName>
<NetbiosComputerName>$Config/NetbiosComputerName$</NetbiosComputerName>
<InstanceName>$Config/InstanceName$</InstanceName>
<ConnectionString>$Config/ConnectionString$</ConnectionString>
<InstanceVersion>$Config/InstanceVersion$</InstanceVersion>
<InstanceEdition>$Config/InstanceEdition$</InstanceEdition>
<MonitoringType>$Config/MonitoringType$</MonitoringType>
<IncludedJobs>$Config/IncludedJobs$</IncludedJobs>
<SqlExecTimeoutSeconds>$Config/SqlExecTimeoutSeconds$</SqlExecTimeoutSeconds>
<SqlTimeoutSeconds>$Config/SqlTimeoutSeconds$</SqlTimeoutSeconds>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
</DataSource>
<ConditionDetection ID="CDUnderThreshold1" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='MaxJobDuration']</XPathQuery>
</ValueExpression>
<Operator>Less</Operator>
<ValueExpression>
<Value Type="Double">$Config/Threshold1$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDOverThreshold1UnderThreshold2" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='MaxJobDuration']</XPathQuery>
</ValueExpression>
<Operator>GreaterEqual</Operator>
<ValueExpression>
<Value Type="Double">$Config/Threshold1$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='MaxJobDuration']</XPathQuery>
</ValueExpression>
<Operator>LessEqual</Operator>
<ValueExpression>
<Value Type="Double">$Config/Threshold2$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDOverThreshold2" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='MaxJobDuration']</XPathQuery>
</ValueExpression>
<Operator>Greater</Operator>
<ValueExpression>
<Value Type="Double">$Config/Threshold2$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="UnderThreshold1">
<Node ID="CDUnderThreshold1">
<Node ID="DS"/>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="OverThreshold1UnderThreshold2">
<Node ID="CDOverThreshold1UnderThreshold2">
<Node ID="DS"/>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="OverThreshold2">
<Node ID="CDOverThreshold2">
<Node ID="DS"/>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>