This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Custom Alert - Long Running Queries

FormerMember
FormerMember

Description

This alert is for SQL Server instances only and will tell you when SQL statements have executed more than a defined amount of time. This example uses a 300 second threshold, meaning any SQL statements that have been executing for longer than 300 seconds (5 minutes) will be alerted. The alert query executes against the monitored database directly so caution should be taken on how often the alert is executed, especially if less than the default of every 300 seconds.

Definition

To create the alert, click on Alerts > Manage Alerts tab and create a Custom Alert of type Custom SQL Alert - Multiple Numeric Return. Configure the alert with values similar to these:

  • Alert Name: SQL Server - Long Running Queries
  • Execution Interval: 5 Minutes
  • Notification Text: The following list of SQL statements have been running for over 5 minutes.
  • Execute Against: Monitored Database
  • Units: Seconds
  • High Threshold: Minimum 300 (This value must match value found in query. Default: 300 ), MAX empty

SQL Statement

SELECT 'SPID=' + CONVERT(VARCHAR, a.session_id) + ' has been running the following for ' + CONVERT(VARCHAR, DATEDIFF(SS, a.start_time, CURRENT_TIMESTAMP)) + ' seconds: ' + convert(VARCHAR, b.TEXT)
     , CONVERT(VARCHAR, DATEDIFF(SS, a.start_time, CURRENT_TIMESTAMP))
FROM sys.dm_exec_requests a
CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) b
WHERE a.STATUS <> 'background'
     AND DATEDIFF(SS, a.start_time, CURRENT_TIMESTAMP) > 300 --This value of 300 must match the Execution Interval set in the alert

Parents
  • That we can't do.  The query you are running for the alert as defined runs directly against the monitored instance.  The query_plan_hash being selected is directly from the sys.dm_exec_requests DMV and DPA isn't doing it's own hash as it never actually flows through our app (we only show what SQL shows us).

    Sorry about that!

Reply
  • That we can't do.  The query you are running for the alert as defined runs directly against the monitored instance.  The query_plan_hash being selected is directly from the sys.dm_exec_requests DMV and DPA isn't doing it's own hash as it never actually flows through our app (we only show what SQL shows us).

    Sorry about that!

Children
No Data