Monitoring

Scheduled Task Monitoring

Windows Scheduled Task monitoring is easy with Cronitor. Our web dashboard provides you with better visibility into your tasks, and we'll send instant alerts if any goes wrong, including:

  • The task does not start on schedule
  • The task fails or crashes unexpectedly
  • The task runs longer than expected

How to Create a Windows Scheduled Task Monitor

There are two ways to create Scheduled Task monitors with Cronitor.

  1. Use the web dashboard to create individual monitors.

    Our web dashboard is an easy to use interface, and creating new monitors can be done quickly by anyone with a Cronitor account.

  2. Integrate with our Monitor API to programatically create monitors.

    For more advanced use cases, such as adding Cronitor to provisioning or deployment scripts, we offer an easy to use REST API as well as open-source API clients for many popular languages.

  1. First, determine the schedule that your task is running on. This can be found in the Task Scheduler interface. In this example, the task runs every 2 minutes.

  2. From the Cronitor dashboard, click the button to create a new monitor and select Scheduled Task
  3. Add a Complete endpoint not pinged in 2 minutes rule. Optionally, add a Runs for longer than rule to identify tasks that run longer than expected.
  4. Give the monitor a descriptive name like Offsite Backup and add optional tags or notes and hit "Save".
  5. You're done! Your monitor will be assigned a unique ping url and be placed in a pending state. Monitoring will begin when the first ping is received.

  1. First, determine the schedule that your task is running on. This can be found in the Task Scheduler interface. In this example, the task runs every 2 minutes.

  2. Copy your API key from your settings page.
  3. Add a not_completed_in 2 minutes rule. Optionally, add a ran_longer_than rule to identify tasks that run longer than expected.

    Use cURL or one of our open-source API clients to make a POST request.

    curl -X POST https://cronitor.io/v3/monitors -u <API-KEY>: -d '{
        "name": "Offsite Backup",
        "type": "scheduled_task",
        "rules": [
            {
                "rule_type": "not_completed_in",
                "value": "2",
                "time_unit": "minutes"
            },
            {
                "rule_type": "ran_longer_than",
                "value": 45,
                "time_unit": "seconds"
            }
        ]
    }' -H "Content-Type: application/json"
    

    Tip: Complete documenation for our Monitor API can be found here.

  4. You're done! Your monitor will be assigned a unique ping url and be placed in a pending state. Monitoring will begin when the first ping is received.

Adding Cronitor to your Scheduled Task

On your server, download the CronitorCLI application. We recommend moving the executable to %SystemDrive%\Program Files\ for system-wide use. From the Task Scheduler, update the scheduled task action you are monitoring to invoke CronitorCLI:

  1. Right click the desired scheduled task, select Properties, select Actions, select the first action listed, click "Edit".
  2. Turn the command being invoked into an argument to cronitor exec. In this example you see that the C:\app\bin\collect-stats command is now being passed as an argument to CronitorCLI. the first argument after exec, d3x0c1, is the unique code for this monitor, copied from the Cronitor dashboard.

    Program/script Arguments
    Before integration C:\app\bin\collect-stats PRODUCTION
    After integration C:\Program Files\cronitor.exe exec d3x0c1 C:\app\bin\collect-stats PRODUCTION

    Before you are running C:\app\bin\collect-stats directly:


    After integration you are using CronitorCLI to run the command:
  3. If your scheduled task has multiple actions listed, repeat this step for each action.
  4. If possible, run your task manually from the Task Scheduler to ensure that it works properly. You should see the details from the run on your Cronitor dashboard within a few seconds.

Tip: Cronitor integration can be accomplished without installing CronitorCLI. To do this, move your current command and arguments to a .bat file, and using curl or similar to ping to your monitor's unique /run endpoint before your task runs, and ping /complete after it exits.

How to Configure Alert Recipients

Cronitor can send alerts via many different channels, including: Email, Slack, PagerDuty, Microsoft Teams, SMS, webhooks and more.

Notification lists are configurable sets of channels that are attached to your monitors. When a monitor fails or recovers, an alert will be sent to every channel/recipient on the attached list. You can create or modify a list from the Notification Lists section of your settings page.

In the monitor's edit form locate the Alert Receipients panel. You may choose to add a notification list or add channels/recipients directly (or both).

Specify alert recipients adding a notifications object to your monitor JSON as shown below. Notification lists are attached using the template key. For complete list of options see our API docs.

curl -X POST https://cronitor.io/v3/monitors -u <API-KEY>: -d '{
    "name": "Database Backup",
    "type": "cron",
    "rules": [
    {
    "rule_type": "not_on_schedule",
    "value": "0 */3 * * 1-5"
    },
    ],
    notifications: {
    templates: ['devops-emergency'],
    slack: ['https://hooks.slack.com/2af3bvbnjwg9882']
    phone: ['+1555-555-5555']
    }

    }' -H "Content-Type: application/json"
            

Tip: When your Cronitor account is created a list named "Default" will automatically be created, and your email address will be added to it. When no list is specified the default list will be used.

How to Customize Failure Tolerance Alerts

By default Cronitor will alert you every time we detect a problem. If you can tolerate a few failures, and do not wish be alerted each time, you can set the failure tolerance threshold of your monitor. You will be sent an alert when the number of consecutive failures exceededs the threshold.

In the monitor's edit form locate the Alert Preferences panel and select Failure Tolerance. Choose "Only send an alert if there is a persistent problem". Set the failure tolerance as desired.

Specify failure tolerance by adding the key tolerated_failures to your monitor's JSON object. The value is the threhold number.

curl -X POST https://cronitor.io/v3/monitors -u <API-KEY>: -d '{
"name": "Database Backup",
"type": "cron",
"tolerated_failures": 5,
"rules": [
{
    "rule_type": "not_on_schedule",
    "value": "0 */3 * * 1-5"
}
]
}' -H "Content-Type: application/json"