Position correctly - Place pings at the very end of your success path
Use source headers - Help identify which system sent the ping
Checkly records that a ping arrived, plus its User-Agent and Origin or Referer header. A request body is ignored, so any job metadata sent in the examples below isn’t stored in Checkly.
Shell Scripts and Command Line
Basic cURL Examples
The most common way to ping Heartbeat monitors from shell scripts:
# Basic GET request with timeout and retrycurl -m 5 --retry 3 https://ping.checklyhq.com/your-heartbeat-id# With source identificationcurl -m 5 --retry 3 \ -H "Origin: backup-server-prod" \ https://ping.checklyhq.com/your-heartbeat-id# Silent operation (no output)curl -m 5 --retry 3 -s \ https://ping.checklyhq.com/your-heartbeat-id
# POST request (the request body is ignored)curl -X POST -m 5 --retry 3 \ -H "Content-Type: application/json" \ -d '{"job":"backup", "duration": 120, "files": 1500}' \ https://ping.checklyhq.com/your-heartbeat-id
# Only ping if previous command succeededrun_backup.sh && curl -m 5 --retry 3 https://ping.checklyhq.com/your-heartbeat-id# More robust error handlingif run_backup.sh; then echo "Backup successful, sending heartbeat ping" curl -m 5 --retry 3 https://ping.checklyhq.com/your-heartbeat-idelse echo "Backup failed, no ping sent" exit 1fi
wget Alternative
If cURL isn’t available, use wget instead:
# Basic wget with timeout and retrywget -T 5 -t 3 -q -O /dev/null \ https://ping.checklyhq.com/your-heartbeat-id# In a complete backup script#!/bin/bashset -e # Exit on any errorecho "Starting database backup..."pg_dump production_db > /tmp/backup.sqlecho "Uploading to S3..."aws s3 cp /tmp/backup.sql s3://backups/$(date +%Y%m%d).sqlecho "Cleaning up..."rm /tmp/backup.sqlecho "Sending success ping..."wget -T 5 -t 3 -q -O /dev/null \ https://ping.checklyhq.com/your-heartbeat-idecho "Backup completed successfully!"
Platform-Specific Integrations
Heroku Scheduler
Monitor Heroku scheduled tasks:
# In your Heroku Scheduler commandrun_task.sh && curl -m 5 --retry 3 https://ping.checklyhq.com/your-heartbeat-id
Render Cron Jobs
For Render cron job services:
#!/bin/bash# Render cron job script# Run your taskpython process_data.py# Only ping if successful (exit code 0)if [ $? -eq 0 ]; then curl -m 5 --retry 3 https://ping.checklyhq.com/your-heartbeat-idfi
Railway Cron Jobs
Similar pattern for Railway scheduled deployments:
# In your railway cron scriptnpm run data-sync && \curl -m 5 --retry 3 https://ping.checklyhq.com/your-heartbeat-id
Kubernetes Cron Jobs
Basic CronJob with Heartbeat
apiVersion: batch/v1kind: CronJobmetadata: name: nightly-backup namespace: productionspec: schedule: "0 2 * * *" # 2 AM daily successfulJobsHistoryLimit: 3 failedJobsHistoryLimit: 3 jobTemplate: spec: backoffLimit: 2 template: spec: containers: - name: backup-job image: your-registry/backup-job:latest command: - /bin/sh - -c args: - | echo "Running backup job..." # Run your actual backup logic /scripts/run-backup.sh # Only ping if backup succeeded if [ $? -eq 0 ]; then echo "Backup successful, sending heartbeat..." curl -m 5 --retry 3 \ -H "Origin: k8s-cluster-prod" \ https://ping.checklyhq.com/your-heartbeat-id else echo "Backup failed, no heartbeat sent" exit 1 fi restartPolicy: OnFailure
Advanced CronJob with Sidecar
For more complex scenarios, use a sidecar pattern:
apiVersion: batch/v1kind: CronJobmetadata: name: data-processingspec: schedule: "0 */6 * * *" # Every 6 hours jobTemplate: spec: template: spec: containers: # Main job container - name: processor image: your-app/data-processor:latest command: ["/app/process-data"] volumeMounts: - name: shared-status mountPath: /shared # Heartbeat sidecar - name: heartbeat image: curlimages/curl:latest command: - /bin/sh - -c - | # Wait for main container to finish while [ ! -f /shared/status ]; do sleep 5 done # Check if job succeeded if [ "$(cat /shared/status)" = "success" ]; then curl -m 5 --retry 3 \ https://ping.checklyhq.com/your-heartbeat-id fi volumeMounts: - name: shared-status mountPath: /shared volumes: - name: shared-status emptyDir: {} restartPolicy: OnFailure
Node.js and JavaScript
Built-in HTTPS Module
import https from 'https';async function pingHeartbeat(url: string): Promise<void> { return new Promise((resolve, reject) => { const options = { timeout: 5000, }; const req = https.get(url, options, (res) => { console.log(`Heartbeat ping status: ${res.statusCode}`); resolve(); }); req.on('error', (error) => { console.error(`Heartbeat ping failed: ${error.message}`); reject(error); }); req.on('timeout', () => { req.destroy(); reject(new Error('Heartbeat ping timeout')); }); });}// Usage in your jobasync function runScheduledJob() { try { // Your job logic here await processData(); await generateReports(); // Only ping on success await pingHeartbeat('https://ping.checklyhq.com/your-heartbeat-id'); console.log('Job completed successfully'); } catch (error) { console.error('Job failed:', error); // Don't ping on failure - let heartbeat monitor alert process.exit(1); }}
Sometimes you only want to ping under certain conditions:
def conditional_heartbeat_example(): """Only ping heartbeat if certain conditions are met.""" # Run your job results = process_data() # Only ping if we processed a significant amount of data if results['processed_count'] > 100: ping_heartbeat( url="https://ping.checklyhq.com/your-heartbeat-id", metadata={'processed': results['processed_count']} ) print(f"Heartbeat sent - processed {results['processed_count']} items") else: print(f"Skipped heartbeat - only processed {results['processed_count']} items")
Multi-Step Job Monitoring
For complex jobs with multiple phases:
#!/bin/bashset -eHEARTBEAT_URL="https://ping.checklyhq.com/your-heartbeat-id"JOB_FAILED=false# Function to send heartbeat on successsend_success_heartbeat() { if [ "$JOB_FAILED" = false ]; then curl -m 5 --retry 3 -H "Origin: multi-step-job" "$HEARTBEAT_URL" echo "Success heartbeat sent" fi}# Trap to ensure heartbeat is sent on successful completiontrap send_success_heartbeat EXIT# Step 1: Download dataecho "Step 1: Downloading data..."if ! download_data.sh; then echo "Data download failed" JOB_FAILED=true exit 1fi# Step 2: Process data echo "Step 2: Processing data..."if ! process_data.sh; then echo "Data processing failed" JOB_FAILED=true exit 1fi# Step 3: Upload resultsecho "Step 3: Uploading results..."if ! upload_results.sh; then echo "Results upload failed" JOB_FAILED=true exit 1fiecho "All steps completed successfully"# Heartbeat will be sent by the EXIT trap
Troubleshooting
Common Issues
Network Timeouts
Problem: Pings fail due to network timeouts or slow connections.Solution: Always configure timeouts and retries:
Problem: Pings are ignored due to blocked user agents.Blocked user agents: Twitterbot, Slackbot, Googlebot, Discordbot, Facebot, TelegramBot, WhatsApp, LinkedInBotSolution: Use custom user agents:
curl -A "MyApp/1.0" https://ping.checklyhq.com/your-id
Wrong HTTP Methods
Problem: Using unsupported HTTP methods.Supported: GET, POST Not supported: PUT, DELETE, PATCHSolution: Stick to GET or POST:
# Goodrequests.get(heartbeat_url)requests.post(heartbeat_url, json=metadata)# Bad - will return errorrequests.put(heartbeat_url)
Timing in Error Handling
Problem: Pings sent even when job fails.Solution: Structure your code correctly:
# Good: Ping only on successtry: run_job() ping_heartbeat() # Only reached if run_job() succeedsexcept Exception: # Don't ping on failure logging.error("Job failed")# Bad: Always pingstry: run_job()except Exception: logging.error("Job failed")finally: ping_heartbeat() # Always runs!
Testing Your Implementation
Before deploying, test your heartbeat integration:
Manual ping test: Use the Checkly UI to send manual pings
Timeout test: Temporarily block network access to verify timeout behavior
Failure test: Force your job to fail and confirm no ping is sent
Retry test: Add temporary network delays to test retry logic
Start with a short grace period (like 5 minutes) while testing, then increase it to your production requirements once you’re confident in the timing.