MSSQL on Windows: Long Running Queries Alert Rule

Microsoft.SQLServer.Windows.AlertRule.LongRunningQueries (Rule)

Throws an alert if the execution time of any running SQL queries has exceeded the specified threshold (in seconds). 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 the running SQL queries has exceeded the specified threshold (in seconds).

Note that this rule doesn't provide the texts of executing queries due to security reasons.

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 (seconds)

Threshold that defines the amount of time (in seconds) that is acceptable for a SQL query to be executing. Every time this threshold is exceeded, an alert is thrown.

60

Top number of queries

Threshold that defines the top number of queries with a long execution time will be shown in the alert.

5

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.DBEngine
CategoryAlert
EnabledFalse
Alert GenerateTrue
Alert SeverityWarning
Alert PriorityNormal
RemotableTrue
Alert Message
MSSQL on Windows: Query execution duration exceeded the threshold
The longest execution time of a query on SQL Server instance "{1}", computer "{0}" has exceeded the specified threshold. See the "Alert Context" tab for more details.

Member Modules:

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

Source Code:

<Rule ID="Microsoft.SQLServer.Windows.AlertRule.LongRunningQueries" Target="SqlDiscW!Microsoft.SQLServer.Windows.DBEngine" Enabled="false">
<Category>Alert</Category>
<DataSources>
<DataSource ID="DS" TypeID="Microsoft.SQLServer.Windows.DataSource.LongRunningQueries">
<MachineName>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</MachineName>
<NetbiosComputerName>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/NetbiosComputerName$</NetbiosComputerName>
<InstanceName>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</InstanceName>
<Threshold>60</Threshold>
<TopQueries>5</TopQueries>
<ConnectionString>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/ConnectionString$</ConnectionString>
<InstanceVersion>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/Version$</InstanceVersion>
<InstanceEdition>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/Edition$</InstanceEdition>
<MonitoringType>$Target/Property[Type="SqlDiscW!Microsoft.SQLServer.Windows.DBEngine"]/MonitoringType$</MonitoringType>
<SqlExecTimeoutSeconds>60</SqlExecTimeoutSeconds>
<SqlTimeoutSeconds>15</SqlTimeoutSeconds>
<TimeoutSeconds>300</TimeoutSeconds>
<IntervalSeconds>900</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.LongRunningQueries.AlertMessage"]$</AlertMessageId>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</AlertParameter1>
<AlertParameter2>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</AlertParameter2>
<AlertParameter3>$Data/Property[@Name='MaxDurationSec']$</AlertParameter3>
<AlertParameter4>$Data/Property[@Name='RequestList']$</AlertParameter4>
</AlertParameters>
<Suppression>
<SuppressionValue/>
</Suppression>
</WriteAction>
</WriteActions>
</Rule>