长时间运行的作业

Microsoft.SQLServer.2012.Agent.LongRunningJobs (UnitMonitor)

此监视器检查长期运行的 SQL 代理作业。
请注意,任何版本的 SQL Server Express 均不支持 SQL Server 代理 Windows 服务,没有合适的发现对象。此监视器在默认情况下为禁用。请在必要时使用替代启用该监视器。

Knowledge Base article:

摘要

此监视器检查长期运行的 SQL 代理作业。如果作业的运行时间超出配置的阈值,将生成一个警告或错误警报。

原因

不正常状态是由运行时间超出定义的阈值的 SQL Server 代理作业引起的。这可能表示作业存在问题。

SQL Server 代理负责运行计划在特定时间或间隔发生的 SQL Server 任务,还负责检测管理员已为其定义了操作的特定情况(例如通过页面或电子邮件向某人发出警报)或将解决此情况的任务。SQL Server 代理还用于运行管理员定义的复制任务。

要确定引起警告或错误状态的作业,请检查状态更改或警报的上下文。

解决方法

检查 SQL Server Management Studio 以确定正在运行哪些作业。如果这些作业运行的时间过长,请对它们进行调查以查明原因。

使用 sp_help_jobactivity 以查看有关当前正在运行作业的信息。

或者,如果期望某些代理作业长时间运行:

可替代参数

名称

说明

默认值

警报优先级

定义警报优先级。

正常

警报严重性

定义警报严重性。

MatchMonitorHealth

已启用

启用或禁用工作流。

生成警报

定义工作流是否生成警报。

间隔(秒)

此监视器使用脚本对长期运行的作业进行监视。这是执行该脚本的时间间隔(秒)。

600

阈值下限(分钟)

该监视器的阈值下限(分钟)。默认情况下,超过该阈值至少会导致监视器进入警告状态。

60

同步时间

使用 24 小时格式指定的同步时间。可以忽略。

 

超时(秒)

指定允许工作流在被关闭并标记为失败之前运行的时间。

300

阈值上限(分钟)

该监视器的阈值上限(分钟)。默认情况下,超过该阈值会导致监视器进入严重状态。介于该阈值与阈值下限(包括下限)之间会导致(默认情况下)监视器处于警告状态。

120

Element properties:

TargetMicrosoft.SQLServer.2012.Agent
Parent MonitorSystem.Health.PerformanceState
CategoryPerformanceHealth
EnabledFalse
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.SQLServer.2012.AgentLongRunningJobsProvider
RemotableTrue
AccessibilityPublic
Alert Message
长时间运行的作业
计算机 {0} 上的 SQL 实例 {1} 上有长时间运行的代理作业。这可能表示一个或多个作业存在问题。
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.SQLServer.2012.Agent.LongRunningJobs" Accessibility="Public" Enabled="false" Target="SQL2012Core!Microsoft.SQLServer.2012.Agent" ParentMonitorID="SystemHealth!System.Health.PerformanceState" Remotable="true" Priority="Normal" TypeID="Microsoft.SQLServer.2012.AgentLongRunningJobsProvider" ConfirmDelivery="false">
<Category>PerformanceHealth</Category>
<AlertSettings AlertMessage="Microsoft.SQLServer.2012.Agent.LongRunningJobs.AlertMessage">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</AlertParameter1>
<AlertParameter2>$Target/Host/Property[Type="SQL!Microsoft.SQLServer.ServerRole"]/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>
<IntervalSeconds>600</IntervalSeconds>
<SyncTime/>
<ConnectionString>$Target/Host/Property[Type="SQL!Microsoft.SQLServer.DBEngine"]/ConnectionString$</ConnectionString>
<Threshold1>60</Threshold1>
<Threshold2>120</Threshold2>
<TimeoutSeconds>300</TimeoutSeconds>
</Configuration>
</UnitMonitor>