Job Duration

Microsoft.SQLServer.Windows.Monitor.AgentJob.Duration (UnitMonitor)

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

Knowledge Base article:

Summary

This monitor checks all jobs on the SQL Agent and if any of the jobs takes longer than the specified threshold, the monitor changes its state either to Warning or Critical. This does not generate an alert because there is an override to disable alerts to control noise. If you want this level of monitoring, you need to override Alerting back to enabled. Note: The SQL Agent job duration is reset automatically after restarting the SQL Server Agent service. This can cause the monitor state to be changed from either Warning or Critical to Healthy.

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 changes its state to 'Critical' if the value drops below this threshold. The monitor reports the 'Warning' state if the health state is between this threshold and 'Warning Threshold (minutes)'.

120

Enabled

Enables or disables the workflow.

Yes

Generates Alerts

Defines whether the workflow generates an Alert.

No

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

The monitor changes its state to 'Warning' if the value drops below this threshold.

60

Element properties:

TargetMicrosoft.SQLServer.Windows.AgentJob
Parent MonitorSystem.Health.PerformanceState
CategoryPerformanceCollection
EnabledTrue
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.SQLServer.Windows.MonitorType.AgentJob.Duration
RemotableTrue
AccessibilityPublic
Alert Message
MSSQL on Windows: Agent Job Duration Critical
The SQL Server Agent job "{2}" is being executed for "{3}" minute(s) on SQL Server instance "{1}", computer "{0}".
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.SQLServer.Windows.Monitor.AgentJob.Duration" Accessibility="Public" Enabled="true" Target="SqlDiscW!Microsoft.SQLServer.Windows.AgentJob" ParentMonitorID="Health!System.Health.PerformanceState" Remotable="true" Priority="Normal" TypeID="Microsoft.SQLServer.Windows.MonitorType.AgentJob.Duration" ConfirmDelivery="false">
<Category>PerformanceCollection</Category>
<AlertSettings AlertMessage="Microsoft.SQLServer.Windows.Monitor.AgentJob.Duration.AlertMessage">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
<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/Context/Property[@Name='Duration']$</AlertParameter4>
</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/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>
<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>
<JobName>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.AgentJob"]/Name$</JobName>
<Threshold1>60</Threshold1>
<Threshold2>120</Threshold2>
<SqlTimeoutSeconds>15</SqlTimeoutSeconds>
<TimeoutSeconds>300</TimeoutSeconds>
<IntervalSeconds>600</IntervalSeconds>
<SyncTime/>
</Configuration>
</UnitMonitor>