MSSQL on Windows: SQL Server Agent Job Duration Alert Rule

Microsoft.SQLServer.Windows.AlertRule.AgentJob.Duration (Rule)

This rule throws an alert if the execution time of any of your SQL Agent jobs has exceeded the specified threshold (in minutes). Note that this rule is disabled by default. Use overrides to enable it when necessary.

Knowledge Base article:

Summary

This rule checks whether the execution time of any of your SQL Agent jobs has exceeded the specified threshold (in minutes). This rule is disabled by default. Use overrides to enable it when necessary.

Note that SQL Server Agent Windows Service is not supported by any edition of SQL Server Express.

Overridable Parameters

Name

Description

Default Value

Enabled

Enables or disables the workflow.

No

Interval (seconds)

The recurring interval of time in seconds in which to run the workflow.

600

Priority

Defines alert priority.

1

Severity

Defines alert severity.

1

Synchronization Time

The synchronization time specified by using a 24-hour format. Can be omitted.

 

Threshold (minutes)

Threshold that defines the amount of time (in minutes) that is acceptable for the SQL Agent job to be running. Every time this threshold is exceeded, an alert is thrown.

60

Timeout (seconds)

Specifies the time the workflow is allowed to run before being closed and marked as failed.

300

Timeout for query execution (seconds)

The workflow will fail and register an event, if the query execution takes longer than the specified period.

60

Timeout for database connection (seconds)

The workflow will fail and register an event, if it cannot access the database during the specified period.

15

Element properties:

TargetMicrosoft.SQLServer.Windows.AgentJob
CategoryAlert
EnabledFalse
Alert GenerateTrue
Alert SeverityWarning
Alert PriorityNormal
RemotableTrue
Alert Message
MSSQL on Windows: Agent Job duration exceeded the threshold
The execution time of the SQL Server Agent job "{2}" on SQL Server instance "{1}", computer "{0}" has exceeded the specified threshold.

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.SQLServer.Windows.DataSource.AgentJobDurationCondition Default
GenerateAlert WriteAction System.Health.GenerateAlert Default

Source Code:

<Rule ID="Microsoft.SQLServer.Windows.AlertRule.AgentJob.Duration" Target="SqlDiscW!Microsoft.SQLServer.Windows.AgentJob" Enabled="false">
<Category>Alert</Category>
<DataSources>
<DataSource ID="DS" TypeID="Microsoft.SQLServer.Windows.DataSource.AgentJobDurationCondition">
<MachineName>$Target/Host/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</MachineName>
<NetbiosComputerName>$Target/Host/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/NetbiosComputerName$</NetbiosComputerName>
<InstanceName>$Target/Host/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</InstanceName>
<JobName>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.AgentJob"]/Name$</JobName>
<Threshold>60</Threshold>
<ConnectionString>$Target/Host/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/ConnectionString$</ConnectionString>
<InstanceVersion>$Target/Host/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/Version$</InstanceVersion>
<InstanceEdition>$Target/Host/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/Edition$</InstanceEdition>
<MonitoringType>$Target/Host/Host/Property[Type="SqlDiscW!Microsoft.SQLServer.Windows.DBEngine"]/MonitoringType$</MonitoringType>
<SqlExecTimeoutSeconds>60</SqlExecTimeoutSeconds>
<SqlTimeoutSeconds>15</SqlTimeoutSeconds>
<TimeoutSeconds>300</TimeoutSeconds>
<IntervalSeconds>600</IntervalSeconds>
<SyncTime/>
</DataSource>
</DataSources>
<WriteActions>
<WriteAction ID="GenerateAlert" TypeID="Health!System.Health.GenerateAlert">
<Priority>1</Priority>
<Severity>1</Severity>
<AlertMessageId>$MPElement[Name="Microsoft.SQLServer.Windows.AlertRule.AgentJob.Duration.AlertMessage"]$</AlertMessageId>
<AlertParameters>
<AlertParameter1>$Target/Host/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</AlertParameter1>
<AlertParameter2>$Target/Host/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</AlertParameter2>
<AlertParameter3>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.AgentJob"]/Name$</AlertParameter3>
<AlertParameter4>$Data/Property[@Name='Duration']$</AlertParameter4>
</AlertParameters>
<Suppression>
<SuppressionValue/>
</Suppression>
</WriteAction>
</WriteActions>
</Rule>