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
- Create a heartbeat check in upti.my and receive a unique ping URL
- Configure your cron job or scheduled task to send an HTTP request to the ping URL after each successful run
- upti.my records each heartbeat and tracks whether they arrive on time
- 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:
https://agents.upti.my/v1/heartbeat/your-tokenReplace 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
# 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-tokenIn a Cron Job
# 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
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:
| Field | Description |
|---|---|
| Last Heartbeat Timestamp | When the most recent heartbeat was received |
| Time Since Last | Duration since the last heartbeat was received |
| Source IP | IP address that sent the heartbeat |
| User-Agent | The User-Agent header from the heartbeat request |
| HTTP Method | The HTTP method used (GET, POST, etc.) |
| Content-Type | The Content-Type header from the request |
| Headers | All HTTP headers sent with the heartbeat |
| Body | The request body content (if any) |
| Query Parameters | Any query string parameters included in the ping URL |
| Heartbeat Count | Total number of heartbeats received for this check |
| On-Time Status | Whether 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.