Long running task

Custom.Windows.ScheduledTask.LongRunningTask.Monitor (UnitMonitor)

Knowledge Base article:

Summary

Long running task Monitor.

The monitor checks if a scheduled task is taking too long to complete. This monitor is disabled by default.

Configuration

Use overrides to:

Causes

The scheduled task is taking longer to complete than expected.

Resolutions

Consider altering the task so that it terminates faster.

Element properties:

TargetCustom.Windows.ScheduledTask
Parent MonitorSystem.Health.PerformanceState
CategoryAvailabilityHealth
EnabledFalse
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeCustom.Windows.ScheduledTask.LongRunningTask.MonitorType
RemotableFalse
AccessibilityPublic
Alert Message
Scheduled Task is running too long
The Scheduled Task {0} is running too long. The task started at {1} and has been running for at least {2} minutes.
RunAsDefault

Source Code:

<UnitMonitor ID="Custom.Windows.ScheduledTask.LongRunningTask.Monitor" Accessibility="Public" Enabled="false" Target="Custom.Windows.ScheduledTask" ParentMonitorID="Health!System.Health.PerformanceState" Remotable="false" Priority="Normal" TypeID="Custom.Windows.ScheduledTask.LongRunningTask.MonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="Custom.Windows.ScheduledTask.LongRunningTask.Monitor.AlertMessage">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="SchTaskLib!Custom.Windows.TaskSchedulerTask"]/TaskName$</AlertParameter1>
<AlertParameter2>$Data/Context/Property[@Name='SchTask:$Target/Property[Type="SchTaskLib!Custom.Windows.TaskSchedulerTask"]/TaskName$:LastRun']$</AlertParameter2>
<AlertParameter3>$Data/Context/Property[@Name='SchTask:$Target/Property[Type="SchTaskLib!Custom.Windows.TaskSchedulerTask"]/TaskName$:Duration']$</AlertParameter3>
<AlertParameter4>$Target/Property[Type="Custom.Windows.ScheduledTask"]/TaskSchedule$</AlertParameter4>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="UnderThreshold" MonitorTypeStateID="UnderThresh" HealthState="Success"/>
<OperationalState ID="OverThreshold" MonitorTypeStateID="OverThresh" HealthState="Warning"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>68</IntervalSeconds>
<TargetComputerName>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</TargetComputerName>
<TimeoutSeconds>59</TimeoutSeconds>
<TaskName>$Target/Property[Type="SchTaskLib!Custom.Windows.TaskSchedulerTask"]/TaskName$</TaskName>
<Threshold>60</Threshold>
<TaskState>$Target/Property[Type="Custom.Windows.ScheduledTask"]/TaskState$</TaskState>
</Configuration>
</UnitMonitor>