Monitor Windows Scheduled Tasks
Windows scheduled task monitoring is easy with Cronitor. By updating your scheduled action to ping Cronitor
before and after your task you'll gain visibility with a web dashboard and receive alerts of any noncompliance with the schedule, including:
- The job does not run when expected
- The job runs for longer than expected
Creating a scheduled task monitor
Monitoring scheduled tasks can be completed in just a few minutes, no coding required.
- First, determine the frequency of the scheduled task. The schedule is displayed in the interface. In this example, the task runs every 2 minutes. For tasks with complicated schedules or multiple schedules, please contact support to discuss implementation options.
- From your dashboard, click the button to create a new monitor and select Heartbeat
- Add a "Complete endpoint not pinged in 2 minutes" rule. Optionally, add a "Ran for longer than" rule to identify tasks that run longer than expected.
- Add at least one notification method across Email, SMS, Slack, Hipchat, PagerDuty, etc
- Give the monitor a descriptive name like Offsite Backup and add optional tags or notes
- Save the monitor and you will be given a unique ping URL.
Your new monitor is created in a paused state; monitoring will not begin until the first ping is received.
Integrating your scheduled task monitor
On your server, you will need to create a new .bat file that will be used to run your existing scheduled task command and report the status to Cronitor:
- Create or select a folder to contain .bat files for each scheduled task you wish to monitor.
- We recommend using the open source Wget for Windows to make Cronitor ping requests. Download the 32 or 64bit executable into the folder from the previous step.
- Create a new .bat file using the template below. Update the appropriate path to
wget64.exe and the
UNIQUE-URL-CODE provided by Cronitor when your monitor was created.
C:\ScheduledTasks\wget64.exe -q https://cronitor.link/%code%/run
C:\ScheduledTasks\wget64.exe -q https://cronitor.link/%code%/complete
- From the Task Scheduler, copy the scheduled task action into the .bat script. To find this, right click the desired scheduled task, select Properties, select Actions,
select the first action listed, click "Edit", and then copy both the command itself and any arguments listed to the same line in your .bat script. In the example screenshot below,
you would replace
SCHEDULED-TASK-ACTION in your bat script with
C:\app\bin\collect-stats PRODUCTION. If your scheduled task
has multiple actions listed, repeat this step for each action.
- If your Scheduled Task does not run as an administrator, ensure the RunAs user can execute the recently created .bat file.
- Update your task action to invoke the newly created .bat file:
- If possible, run your task manually from the Task Scheduler to ensure that it works properly.