upti.my

Heartbeat Monitoring

Push-based monitoring for cron jobs, batch processes, and scheduled tasks. Get alerted when expected heartbeats are missed.

Overview

Heartbeat monitoring works differently from other health check types. Instead of upti.my reaching out to check your service (pull-based), your service sends periodic signals to upti.my (push-based). If an expected heartbeat is not received within the configured window, upti.my triggers an alert.

This is the ideal monitoring approach for cron jobs, batch processes, scheduled tasks, background workers, data pipelines, and any process that runs on a schedule. These workloads cannot be effectively monitored with pull-based checks because there is no persistent endpoint to probe.

How It Works

  1. Create a heartbeat check in upti.my and receive a unique ping URL
  2. Configure your cron job or scheduled task to send an HTTP request to the ping URL after each successful run
  3. upti.my records each heartbeat and tracks whether they arrive on time
  4. If a heartbeat is missed (not received within the expected interval), an alert is triggered

Ping URL

Each heartbeat check has a unique URL that your service pings:

Heartbeat Ping URL
https://agents.upti.my/v1/heartbeat/your-token

Replace your-token with the unique token assigned to your heartbeat check. You can find this token in your check's configuration page in the upti.my dashboard.

Sending Heartbeats

Sending a heartbeat is as simple as making an HTTP request to your ping URL. Any HTTP method works, but GET and POST are most common.

Using curl

Curl Example
# Simple heartbeat ping
curl -s https://agents.upti.my/v1/heartbeat/your-token

# Heartbeat with custom body (e.g., job result)
curl -s -X POST \
  -H "Content-Type: application/json" \
  -d '{"status":"completed","records_processed":1500}' \
  https://agents.upti.my/v1/heartbeat/your-token

In a Cron Job

Crontab Entry
# Run backup script every day at 2 AM, then ping heartbeat
0 2 * * * /usr/local/bin/backup.sh && curl -s https://agents.upti.my/v1/heartbeat/your-token

💡 Ping on Success Only

Use && in your cron command to only send the heartbeat if the preceding command succeeds. This way, a failed job will also result in a missed heartbeat, triggering an alert for both job failures and jobs that did not run at all.

In Application Code

Python Example
import requests

def run_scheduled_task():
    # Your task logic here
    process_data()

    # Send heartbeat on completion
    requests.get(
        "https://agents.upti.my/v1/heartbeat/your-token",
        timeout=10
    )

Response Data

Each received heartbeat is recorded with comprehensive metadata:

FieldDescription
Last Heartbeat TimestampWhen the most recent heartbeat was received
Time Since LastDuration since the last heartbeat was received
Source IPIP address that sent the heartbeat
User-AgentThe User-Agent header from the heartbeat request
HTTP MethodThe HTTP method used (GET, POST, etc.)
Content-TypeThe Content-Type header from the request
HeadersAll HTTP headers sent with the heartbeat
BodyThe request body content (if any)
Query ParametersAny query string parameters included in the ping URL
Heartbeat CountTotal number of heartbeats received for this check
On-Time StatusWhether the heartbeat arrived within the expected interval
Latency (ms)How late or early the heartbeat arrived relative to the expected time

Common Use Cases

  • Cron Jobs - Monitor database backups, log rotation, report generation, and cleanup scripts
  • Batch Processes - Track ETL pipelines, data imports, and batch computations
  • Scheduled Tasks - Verify that Windows Task Scheduler or systemd timers run on time
  • Background Workers - Monitor queue consumers, email senders, and async processors
  • Renewal Jobs - Ensure certificate renewals, token rotations, and license checks execute

ℹ️ Rich Heartbeat Data

You can include a JSON body with your heartbeat to record additional context, such as the number of records processed, execution duration, or error counts. This data is stored with the heartbeat and visible in your dashboard for debugging.

⚠️ Network Reliability

If the heartbeat request fails due to a transient network issue, the heartbeat is missed and may trigger a false alert. Consider adding retry logic to your heartbeat pings, especially for critical jobs. A simple retry with a short delay can prevent most false positives.