Palzin monitor cronjob and heartbeat monitoring

Palzin Monitor: Cron Job and Heartbeat Monitoring

Cron job or heartbeat monitoring is an automated way of checking whether scheduled tasks run correctly. It is an ideal monitoring solution for services that perform vital processes periodically.

Palzin Heartbeat Dashboard

Want to get alerted when your cron jobs don't run correctly?

Go to Palzin Monitor and start monitoring your cron jobs in just 2 minutes.

How does cron job monitoring work?

The cron job monitoring process involves setting up a remote monitoring service with a dedicated URL. After a scheduled task runs correctly, it sends a GET, HEAD, or POST request to this URL. This process, known as heartbeat monitoring, tracks the system's health by sending regular requests.

The heartbeat monitor expects to receive a heartbeat within a specified time window. If a heartbeat is received, the monitoring continues. However, if no heartbeat is received when expected, the monitor initiates an incident and starts alerting the appropriate person on the development team based on the on-call calendar.

What is a cron job incident?

A cron job incident occurs when the monitor does not receive heartbeats from the monitored service within the expected time frame. This indicates that the monitored service did not run correctly since all successful runs should send a heartbeat to the monitor.

How to receive cron job incident alerts?

After an incident is detected by the cron job monitor, it needs to be communicated to the service administrators. This process, known as incident alerting or on-call alerting, involves notifying the person who is currently on-call for the team. Various methods can be used for alerting, including automated phone calls, SMS, Slack, and Microsoft Teams messages.

What information do incident alerts include?

Incident alerts for cron jobs and heartbeats provide basic up/down information about the monitoring status. To gain more in-depth insights into potential incidents with scheduled jobs, it is recommended to implement logging in the monitored services and use a log aggregation tool.

The cron job incident resolution process

Once an alert is received, it should be acknowledged immediately. If the alert is not acknowledged within a specified time frame (usually 3 minutes), the next person on the on-call duty is alerted. The goal is to have the on-call schedule set up in a way that the first team member is always ready to handle incoming incidents.

After acknowledging an incident, the escalation process is paused, and the team can focus on resolving the issue. The speed at which an alert is acknowledged is measured as the Time to Acknowledge (TTA), and the average time across different incidents is known as the Mean Time to Acknowledge (MTTA).

The specific steps for resolving a downtime incident may vary depending on the team and the application. Larger teams may involve collaboration between multiple developers or dedicated incident response teams. Best practices for incident management include effective incident communication (both internal and external) and conducting incident post-mortems.

Best practices for cron job monitoring

  • Human alert tolerance: To avoid alert fatigue, only connect vital services to the on-call alerting system and notify the team immediately.
  • Grace time configuration: Configure a grace period to prevent delayed jobs from causing incidents and reduce the risk of alert fatigue. Care should be taken to set an appropriate grace period to avoid delaying incident alerting for actual incidents.
  • Synchronize monitor and cron job timezone: Ensure that the server running cron jobs and the monitoring service are in the same timezone to prevent any timezone differences and faulty alerting.
  • Encrypt communication between monitor and cron job: Use TLS encryption (HTTPS) for communication between the service and the heartbeat monitor to ensure the security and authenticity of the heartbeat requests.

Benefits and drawbacks of cron job monitoring

Benefits

  • Automated and continuous: Cron job monitoring tools like Palzin Monitor listen on a dedicated URL continuously and require little maintenance while providing valuable information.
  • Simple setup and usage: Setting up cron job monitoring is quick and straightforward, providing incident information right from the start. It can be applied to various services and use cases since it provides simple up/down information.

Drawbacks

  • Limited incident cause reporting: Cron job monitoring only provides information about the final output and does not reveal the root cause of incidents. To gain a better understanding of incident causes, additional tools like application performance management (APM) or log management services should be used.
  • Custom code dependency: Setting up cron job monitoring requires custom coding within the script or application, which introduces the possibility of errors and misconfigurations. It is crucial to thoroughly check the setup to ensure its accuracy.

Where does cron job monitoring fit in the monitoring setup?

Cron job monitoring is a valuable addition to the synthetic monitoring toolbox. It complements regular uptime checks, SSL certificate checks, and domain expiration checks to prevent security issues and protect valuable business assets. Synthetic monitoring also offers options like API monitoring, DNS monitoring, and transaction monitoring.

How to start cron job monitoring with Palzin Monitor?

Palzin Monitor is an infrastructure monitoring tool that includes cron job monitoring. Follow these steps to receive alerts whenever a service fails to run correctly, using the example of monitoring a database backup:

Creating a heartbeat monitor

  1. Sign up for Palzin Monitor.
  2. Go to Heartbeats and click on Create heartbeat.
  3. Enter a name for the heartbeat (e.g., "Daily database backup").
  4. Set the expected heartbeat interval to 24 hours.
  5. Set the grace period to the time you expect the database backup to run (e.g., 15 minutes).
  6. Select your preferred method of receiving alerts (e.g., phone call, Slack notification, email).
  7. Click Create monitor.

For more detailed instructions, refer to the Palzin Monitor documentation.

Configuring the cron job

Assuming you have a script for the database backup, you can create a cron job to execute it and send the heartbeat:

  1. Open the crontab file using the command crontab -e.

  2. Append the following line at the end of the file, replacing <your-heartbeat-monitor-id> with the actual URL of your heartbeat monitor:

    0 0 * * * bash /database/backup/script && curl https://palzin.app/api/v1/heartbeat/<your-heartbeat-monitor-id>
    

    The above cron job runs the backup script at midnight every day and sends a heartbeat to the monitor using curl.

Ensure that the heartbeat interval in the cron job matches the expected interval set for the heartbeat monitor.

For more detailed instructions, refer to the Palzin Monitor documentation.

Commonly used cron time period expressions

We notify you when your website experiences downtime

Stay informed with a comprehensive infrastructure monitoring platform

  • Check Uptime, Ping, Ports, SSL, and more.

  • Receive incident alerts via Slack, SMS, and phone.

  • Easily schedule on-call duties.

  • Create a free status page on your own domain.

Explore monitoring →

Last updated: 1 second ago

Want to get started with Palzin Monitor? We offer a no-strings-attached
15 days trial. No credit card required.

It takes less than a minutes to setup your first monitoring.