Long Running Jobs

Microsoft.SQLServer.Windows.Monitor.Agent.LongRunningJobs (UnitMonitor)

This monitor checks for long running SQL Agent jobs. The monitor is disabled by default. Use overrides to enable it when necessary.
Note that SQL Server Agent Service is not supported by any edition of SQL Server Express.

Knowledge Base article:

Summary

This monitor checks for long running SQL Agent jobs. A Warning or Error alert will appear if a job has been running for longer that the configured threshold. Note that this monitor 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.

By default, this monitor does not monitor jobs that have schedule type 'Start automatically when SQL Server Agent starts' because these jobs often run until SQL Agent stops (i.e. continuously). Usually, SQL Server Replication uses such jobs, but in some cases, jobs with the 'Start automatically when SQL Server Agent starts' schedule type may run for a relatively short interval. To monitor these jobs, override parameter 'Included continuously executed jobs' with a comma-delimited list of the job names. The job name in the list should meet requirements of one of the following identifier classes:

1) Regular:

2) Delimited:

Any name belonging to any of the classes above should be from 1 to 128 characters, excluding delimiter characters.

Causes

An unhealthy state is caused by a SQL Server Agent job that has been running longer than the defined threshold. This could indicate a problem with the job.

The SQL Server Agent is responsible for running SQL Server tasks that are scheduled at specific time periods or intervals, as well as detecting specific conditions for which administrators have defined an action, such as alerting someone through pages or email, or a task that will address the conditions. The SQL Server Agent is also used for running replication tasks defined by administrators.

To identify the job that caused the warning or error state, examine the context data for the state change or alert.

Resolutions

Check SQL Server Management Studio to identify what jobs are running. If these jobs are running longer than necessary, investigate them to find out the reason.

Use 'sp_help_jobactivity' to see information about the currently running jobs.

Alternatively, if it is expected for some agent jobs to run for a long time:

Overridable Parameters

Name

Description

Default Value

Alert Priority

Defines Alert Priority.

Normal

Alert Severity

Defines Alert Severity.

Match monitor’s health

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 a Warning state.

120

Enabled

Enables or disables the workflow.

No

Generates Alerts

Defines whether the workflow generates an Alert.

Yes

Included continuously executed jobs

Some 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, the monitor does not consider them. 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.

 

Interval (seconds)

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

600

Synchronization Time

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

 

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

Warning Threshold (minutes)

Exceeding this threshold will result in the monitor changing to at least a Warning state.

60

Element properties:

TargetMicrosoft.SQLServer.Windows.Agent
Parent MonitorSystem.Health.PerformanceState
CategoryPerformanceHealth
EnabledFalse
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.SQLServer.Windows.MonitorType.Agent.LongRunningJobs
RemotableTrue
AccessibilityPublic
Alert Message
MSSQL on Windows: Long Running Jobs
There are long running agent jobs on SQL Server instance "{1}", computer "{0}". This may indicate an issue with one or more jobs.
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.SQLServer.Windows.Monitor.Agent.LongRunningJobs" Accessibility="Public" Enabled="false" Target="SqlDiscW!Microsoft.SQLServer.Windows.Agent" ParentMonitorID="Health!System.Health.PerformanceState" Remotable="true" Priority="Normal" TypeID="Microsoft.SQLServer.Windows.MonitorType.Agent.LongRunningJobs" ConfirmDelivery="false">
<Category>PerformanceHealth</Category>
<AlertSettings AlertMessage="Microsoft.SQLServer.Windows.Monitor.Agent.LongRunningJobs.AlertMessage">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</AlertParameter1>
<AlertParameter2>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</AlertParameter2>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="UnderThreshold1" MonitorTypeStateID="UnderThreshold1" HealthState="Success"/>
<OperationalState ID="OverThreshold1UnderThreshold2" MonitorTypeStateID="OverThreshold1UnderThreshold2" HealthState="Warning"/>
<OperationalState ID="OverThreshold2" MonitorTypeStateID="OverThreshold2" HealthState="Error"/>
</OperationalStates>
<Configuration>
<MachineName>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</MachineName>
<NetbiosComputerName>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/NetbiosComputerName$</NetbiosComputerName>
<InstanceName>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</InstanceName>
<ConnectionString>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/ConnectionString$</ConnectionString>
<InstanceVersion>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/Version$</InstanceVersion>
<InstanceEdition>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/Edition$</InstanceEdition>
<MonitoringType>$Target/Host/Property[Type="SqlDiscW!Microsoft.SQLServer.Windows.DBEngine"]/MonitoringType$</MonitoringType>
<Threshold1>60</Threshold1>
<Threshold2>120</Threshold2>
<IncludedJobs/>
<SqlExecTimeoutSeconds>60</SqlExecTimeoutSeconds>
<SqlTimeoutSeconds>15</SqlTimeoutSeconds>
<TimeoutSeconds>300</TimeoutSeconds>
<IntervalSeconds>600</IntervalSeconds>
<SyncTime/>
</Configuration>
</UnitMonitor>