Help Cron Monitoring

Cron Monitoring

Monitor cron jobs, micro-services, daemons and almost anything else, with a simple no-coding setup. Troubleshoot cron failures quickly and get alerts before a cron failure impacts your system.

Why Monitor Cron Jobs?

Cron jobs are used for scheduling tasks like backups, emails, status checks etc. Thus, these cron jobs can have a major impact on the performance of your web servers and applications. This makes it essential to continuously monitor them and gain insight on important jobs and back-end systems.

With our monitoring solution, you can now have the answers to three of the most important questions related to cron monitoring:

  • How many and which cron jobs are running now or for any given time period?
  • How long have my tasks been running?
  • Are any of my jobs failing, stuck, or running longer than expected?

Add a Cron Monitor

Start tracking your jobs, workers, services, or anything that can send a HTTP request. 

  1. Log in to Site24x7 and go to Server > Cron Monitoring (+).
  2. Enter the following details:
    • Display Name: Enter a name for identification purposes.
    • Cron Expression: These expressions help you schedule your cron jobs. They need to be added in a specific format.
    • Time Zone: Define an appropriate time zone from the drop-down to schedule your cron job.
    • Grace Period: Provide a length of time that defines how soon after initiation an alert can be triggered. This is basically to avoid false alerts due to network delays.
    • Threshold and Availability: Set up threshold profiles to determine when specific resources should be declared critical or down.
  3. Under Advanced Configuration, fill out the following fields:
    • User Alert Group: Decide who has to notified when there is an alert.
    • Tags: Classify and sort related resources in your account by applying unique labels. 
  4. Under Third Party Integration, select from the available integrations to push your monitor alerts into your preferred third party services. Save your changes.
Tip: You can use API to add a cron monitor or download a script to auto-detect and add a cron monitor. Learn more.
Using Cron Expressions

A cron expression allows for greater flexibility, and helps to define fixed time schedules. It consists of five fields, separated by spaces.

Syntax of a Cron Expression:

m   h   dom  mon  dow
*    *      *        *       *        test.sh
|     |     |        |       |
|     |     |        |       #--------- Day of the Week (0 to 6) (Sunday = 0 or 7)
|     |     |        #----------- Month (1 to 12)
|     |     #-------------  Day of the Month (1 to 31)
|     #----------------  Hour (0 to 23)
#-------------------  Minute (0 to 59)                 

Duration Range Description
Minute(s) 0-59 * means every minute at the start of each minute
Hour(s) 0–23 * means every hour at the start of every hour
Day(s) of month 1–31 * means every day
Month(s) 1–12 * means every month, you can use month names if you prefer
Day(s) of week 0–7 0 and 7 both mean Sunday, you can also use names

Examples:

  • Running a backup script named backup.sh located at /etc/script every night at 11pm
    00 23 * * * /etc/script/backup.sh
  • Running a monthly backup script named backup-monthly.sh on the first day of every month at 11:45pm
    45 11 1 * * /etc/script/monthly.sh
  • Using /N interval to have all values in a specified range run in intervals of N, say for every nine minutes (0, 9, 18, 27, 36, 45, 54)
    */9 * * * * 
  • Running a script named test.sh located at /etc/script at 3am and 5am every day
    * 3,5 * * * /etc/script/test.sh
  • Running a script named server.sh located at /etc/script for every hour between 6am to 9am everyday
    * 6-9 * * * /etc/script/server.sh

Setup

Once you have added a cron monitor, you will be redirected to the Setup page automatically. Here, you will find two unique ping URLs listed for your monitor:

  • URL to be pinged before your job starts
    https://plus.site24x7.com/cron/{api key}/{monitor display name/device key}/start
  • URL to be pinged after your job ends
    https://plus.site24x7.com/cron/{api key}/{monitor display name/device key}/end

The complete URL format to collect information when your job starts, completes or fails

https://plus.site24x7.com/cron/{apikey}/{monitor display name/device key}/{ENDPOINT}
 
The monitor will be in the Discovery state, until the first ping is received.

How to Push Data from your Endpoint(s)?

Use one of the following formats to push data from your endpoint(s) and update your job status:

1) Crontab                    2) Bash                     3) Python                    4) PowerShell                     5) Ruby 

Here's an example using Crontab:

Cron URL

Copy the curl command with the ping URL only. Do not forget to replace the path/script.sh with your actual cron to get started.

Alerting for your Cron Jobs

Set up alerts to know if your job, workers, or services runs longer than expected. These alerts will prove beneficial when:

  • Jobs overlap each other (making it difficult to check individual job).
  • You need to check whether an increased customer base or larger database has caused performance degradation over time.  

You can use the unique ping URLs given in the Setup page to send alerts for a particular time period. To do that, ping your /start endpoint when your job starts and your /end endpoint when it successfully completes. In case the runtime of your jobs is varying, you can use a cron expression to specifiy a fixed time duration.

Reports

The following reports are available for cron monitoring:

  • Summary Report - View the overall availability, outage details, availability, and suspended summary for cron monitors. 
    Cron Summary Report
  • Availability Summary Report - View overall availability summary, outage, and downtime of cron monitors, for any chosen period of time.
    Cron Availability Summary Report
  • Health Trend Report - View the availability trend of cron monitors from the time it is initially set up.
    Cron Health Trend Report

Tips to Schedule your Cron Jobs Efficiently 

  • If your jobs don't start as expected, use the Grace Period option and specify an extended time period. 
  • If you receive unexpected alerts for a monitor, check whether you're pinging the /start endpoint before your job starts and the /end endpoint after. A missing or misplaced /start or /end ping is the most common mistake.
  • If you're pinging /start and /end correctly, then try changing the AND (&&) logic in your commands to OR logic (;).
    Try switching from pinging /end only if your command finishes successfully:Cron Expressions
    To always pinging your /end URL:Cron Expressions
    By doing this, you will ping your URL even if your command exits with a non-0 exit code. If that's the case, then find out why your command is exiting with an error code.
  • By using the date command for Linux servers or tzutil /g for Windows, confirm if your server time matches with the timezone set while adding a monitor.

Licensing

This is a basic monitor. 

25 cron monitors = 1 basic monitor = $1

 

Related Articles

Was this document helpful?
Thanks for taking the time to share your feedback. We’ll use your feedback to improve our online help resources.

Help Cron Monitoring